﻿'Description:批次管理业务类
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:Yangsj
'create Date:2017-4-13
'Rewriter:
'Rewrite Date:
Imports BusinessRule.DTO
Imports BusinessRule.IBusiness
Imports DatabaseAccess.DBUtility
Imports Camstar.WebClient.WebServicesProxy.InSiteWebServices
Imports System.Data
Imports System.Text
Imports External.APICalling
Imports System.Data.OracleClient
Imports BusinessRule.Common

Public Class uLMSContainerBusiness
    Implements uLMSContainerIBusiness
    Private m_ConCurrentinfoObj As New uLMSContainercurrentinfoBusiness
    ''' <summary>
    ''' 流水卡建卡
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function StartContainer(ByVal para As DTO.ContainerStartInfo) As ResultStatus Implements IBusiness.uLMSContainerIBusiness.StartContainer
        StartContainer = New ResultStatus

        '创建批次
        Dim m_DataList As New List(Of ClientAPIEntity)
        Dim dataEntity As ClientAPIEntity
        dataEntity = New ClientAPIEntity("ContainerName", InputTypeEnum.Details, DataTypeEnum.DataField, para.ContainerName, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("ContainerType", InputTypeEnum.Details, DataTypeEnum.DataField, para.ContainerType, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("Level", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.Level, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("Product", InputTypeEnum.Details, DataTypeEnum.RevisionedObjectField, para.ProductName, para.ProductRevision)
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("Owner", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.Owner, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("Qty", InputTypeEnum.Details, DataTypeEnum.DataField, para.Qty, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("IsSelfMfg", InputTypeEnum.Details, DataTypeEnum.DataField, para.IsSelfMfg, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("UOM", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.UOM, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("StartReason", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.StartReason, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("Workflow", InputTypeEnum.CurrentStatusDetails, DataTypeEnum.RevisionedObjectField, para.WorkflowName, para.WorkflowRevision)
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("Factory", InputTypeEnum.CurrentStatusDetails, DataTypeEnum.NamedObjectField, para.Factory, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("MfgOrder", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.MfgOrder, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("WorkCenter", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.WorkCenter, "")
        m_DataList.Add(dataEntity)

        If para.Team <> "" Then
            dataEntity = New ClientAPIEntity("Team", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.Team, "")
            m_DataList.Add(dataEntity)
        End If

        dataEntity = New ClientAPIEntity("PriorityCode", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.Priority, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("PlannedStartDate", InputTypeEnum.Details, DataTypeEnum.DataField, para.PlannedStartDate, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("PlannedCompletionDate", InputTypeEnum.Details, DataTypeEnum.DataField, para.PlannedCompletionDate, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("StartEmployee", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, para.StartEmployee, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("ContainerType", InputTypeEnum.Details, DataTypeEnum.DataField, para.ContainerType, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("TogetherFlag", InputTypeEnum.Details, DataTypeEnum.DataField, para.TogetherFlag, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("ContainerComment", InputTypeEnum.Details, DataTypeEnum.DataField, para.Comment, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("MfgBatch", InputTypeEnum.Details, DataTypeEnum.DataField, para.MfgBatch, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("MfgWorkflow", InputTypeEnum.Details, DataTypeEnum.RevisionedObjectField, para.MfgWorkflowName, para.MfgWorkflowRevision)
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("ProductFamilyList", InputTypeEnum.Details, DataTypeEnum.NamedObjectList, para.ProductFamilyList, "")
        m_DataList.Add(dataEntity)

        If Not String.IsNullOrWhiteSpace(para.WorkflowStep) Then
            dataEntity = New ClientAPIEntity("WorkflowStep", InputTypeEnum.CurrentStatusDetails, DataTypeEnum.NamedObjectField, para.WorkflowStep, "")
            m_DataList.Add(dataEntity)
        End If
        If Not String.IsNullOrWhiteSpace(para.YpContainerNo) Then
            dataEntity = New ClientAPIEntity("YpContainerNo", InputTypeEnum.Details, DataTypeEnum.DataField, para.YpContainerNo, "")
            m_DataList.Add(dataEntity)
        End If
        If Not String.IsNullOrWhiteSpace(para.YpHeatNo) Then
            dataEntity = New ClientAPIEntity("YpHeatNo", InputTypeEnum.Details, DataTypeEnum.DataField, para.YpHeatNo, "")
            m_DataList.Add(dataEntity)
        End If
        If Not String.IsNullOrWhiteSpace(para.YpContainerCardNo) Then
            dataEntity = New ClientAPIEntity("YpContainerCardNo", InputTypeEnum.Details, DataTypeEnum.DataField, para.YpContainerCardNo, "")
            m_DataList.Add(dataEntity)
        End If
        If Not String.IsNullOrWhiteSpace(para.YpContainerType) Then '添加叶片类型，add by zhangrj 2021-11-09
            dataEntity = New ClientAPIEntity("YpContainerType", InputTypeEnum.Details, DataTypeEnum.DataField, para.YpContainerType, "")
            m_DataList.Add(dataEntity)
        End If
        If Not String.IsNullOrWhiteSpace(para.MilitaryType) Then '添加军工类型，add by zhangrj 2022-2-16
            dataEntity = New ClientAPIEntity("MilitaryType", InputTypeEnum.Details, DataTypeEnum.DataField, para.MilitaryType, "")
            m_DataList.Add(dataEntity)
        End If

        If Not String.IsNullOrWhiteSpace(para.RbContainerType) Then '添加热表类型，add:Wangjh 20220117
            dataEntity = New ClientAPIEntity("RbContainerType", InputTypeEnum.Details, DataTypeEnum.DataField, para.RbContainerType, "")
            m_DataList.Add(dataEntity)
        End If

        If Not String.IsNullOrWhiteSpace(para.RbTogetherflag) Then '添加热表大批次号，add:Wangjh 20220117
            dataEntity = New ClientAPIEntity("RbTogetherflag", InputTypeEnum.Details, DataTypeEnum.DataField, para.RbTogetherflag, "")
            m_DataList.Add(dataEntity)
        End If

        If Not String.IsNullOrWhiteSpace(para.QualificationQty) Then '添加批次状态 add:Wangjh 20220622
            dataEntity = New ClientAPIEntity("QualificationQty", InputTypeEnum.Details, DataTypeEnum.DataField, para.QualificationQty, "")
            m_DataList.Add(dataEntity)
        End If
        If Not String.IsNullOrWhiteSpace(para.PlannedQty2) Then '添加备件，add by zhangrj 2022-06-28
            dataEntity = New ClientAPIEntity("PlannedQty2", InputTypeEnum.Details, DataTypeEnum.DataField, para.PlannedQty2, "")
            m_DataList.Add(dataEntity)
        End If

        If Not String.IsNullOrWhiteSpace(para.QualificationNum) Then '批次序号，黎阳单件单卡和子序号的批次有值（containername.replace(togetherflag,'')） add:Wangjh 20221115
            dataEntity = New ClientAPIEntity("QualificationNum", InputTypeEnum.Details, DataTypeEnum.DataField, para.QualificationNum, "")
            m_DataList.Add(dataEntity)
        End If

        Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))

        Dim dtChildList As DataTable = para.ChildList

        If Not IsNothing(dtChildList) Then
            For Each child As DataRow In dtChildList.Rows
                Dim m_Child As New List(Of ClientAPIEntity)
                Dim stepEntity As New ClientAPIEntity

                stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                stepEntity.ClientDataName = "ContainerName"
                stepEntity.ClientDataValue = child.Item("ContainerName").ToString
                m_Child.Add(stepEntity)

                stepEntity = New ClientAPIEntity
                stepEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
                stepEntity.ClientDataName = "Level"
                stepEntity.ClientDataValue = para.Level
                m_Child.Add(stepEntity)

                stepEntity = New ClientAPIEntity
                stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                stepEntity.ClientDataName = "Qty"
                stepEntity.ClientDataValue = child.Item("Qty").ToString
                m_Child.Add(stepEntity)

                If dtChildList.Columns.Contains("QualificationNum") Then '批次序号，黎阳单件单卡和子序号的批次有值 add:Wangjh 20221115
                    m_Child.Add(New ClientAPIEntity("QualificationNum", InputTypeEnum.Details, DataTypeEnum.DataField, child.Item("QualificationNum").ToString, ""))
                End If

                If dtChildList.Columns.Contains("TogetherFlag") Then
                    m_Child.Add(New ClientAPIEntity("TogetherFlag", InputTypeEnum.Details, DataTypeEnum.DataField, child.Item("TogetherFlag").ToString, ""))
                End If

                If dtChildList.Columns.Contains("YpContainerType") Then '叶片批次类型，必须和主卡保持一致 add by zhangrj 20230831
                    m_Child.Add(New ClientAPIEntity("YpContainerType", InputTypeEnum.Details, DataTypeEnum.DataField, child.Item("YpContainerType").ToString, ""))
                End If

                If dtChildList.Columns.Contains("RbContainerType") Then '热表批次类型，必须和主卡保持一致 add by zhangrj 20230831
                    m_Child.Add(New ClientAPIEntity("RbContainerType", InputTypeEnum.Details, DataTypeEnum.DataField, child.Item("RbContainerType").ToString, ""))
                End If

                m_ChildList.Add(dtChildList.Rows.IndexOf(child), m_Child)
            Next
        End If

        Dim m_AttributeList As New Dictionary(Of String, List(Of ClientAPIEntity))
        Dim attributeDT As DataTable = para.AttributeList

        For i As Integer = 0 To attributeDT.Rows.Count - 1

            Dim m_AttrChild As New List(Of ClientAPIEntity)
            Dim attEntity As New ClientAPIEntity

            attEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            attEntity.ClientDataName = "Name"
            attEntity.ClientDataValue = attributeDT.Rows(i)("Name")
            m_AttrChild.Add(attEntity)

            attEntity = New ClientAPIEntity()
            attEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            attEntity.ClientDataName = "DataType"
            attEntity.ClientDataValue = "4"
            m_AttrChild.Add(attEntity)

            attEntity = New ClientAPIEntity()
            attEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            attEntity.ClientDataName = "AttributeValue"
            attEntity.ClientDataValue = attributeDT.Rows(i)("Value")
            m_AttrChild.Add(attEntity)

            m_AttributeList.Add(i.ToString().Trim(), m_AttrChild)
        Next
        Dim strInfo As String = ""
        Dim serverUser As String = para.ServerHostInfo.UserName
        Dim serverPassword As String = para.ServerHostInfo.Password

        '创建批次结束
        Dim api As New CamstarClientAPI(serverUser, serverPassword)
        StartContainer.IsError = Not api.StartWithAttributes(m_DataList, m_ChildList, m_AttributeList, strInfo)
        StartContainer.Message = strInfo
    End Function

    ''' <summary>
    ''' 添加批次扩展信息
    ''' </summary>
    ''' <param name="serverHost"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AddExtendAttribute(ByVal attributeDT As DataTable, ByVal serverHost As DTO.ServerHostInfo) As Camstar.WebClient.WebServicesProxy.InSiteWebServices.ResultStatus Implements IBusiness.uLMSContainerIBusiness.AddExtendAttribute
        AddExtendAttribute = New ResultStatus()
        Dim strInfo As String = ""

        Dim m_AttrList As New Dictionary(Of String, List(Of ClientAPIEntity))

        For i As Integer = 0 To attributeDT.Rows.Count - 1

            Dim m_AttrChild As New List(Of ClientAPIEntity)
            Dim attEntity As New ClientAPIEntity

            attEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            attEntity.ClientInputTypeEnum = InputTypeEnum.Details
            attEntity.ClientDataName = "Name"
            attEntity.ClientDataValue = attributeDT.Rows(i)("Name")
            m_AttrChild.Add(attEntity)

            attEntity = New ClientAPIEntity()
            attEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            attEntity.ClientInputTypeEnum = InputTypeEnum.Details
            attEntity.ClientDataName = "DataType"
            attEntity.ClientDataValue = "4"
            m_AttrChild.Add(attEntity)

            attEntity = New ClientAPIEntity()
            attEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            attEntity.ClientInputTypeEnum = InputTypeEnum.Details
            attEntity.ClientDataName = "AttributeValue"
            attEntity.ClientDataValue = attributeDT.Rows(i)("Value")
            m_AttrChild.Add(attEntity)

            m_AttrList.Add(i.ToString().Trim(), m_AttrChild)
        Next

        Dim m_DataList As New List(Of ClientAPIEntity)

        Dim dataEntity As New ClientAPIEntity

        dataEntity.ClientDataTypeEnum = DataTypeEnum.ContainerField
        dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
        dataEntity.ClientDataName = "Container"
        dataEntity.ClientDataValue = attributeDT.Rows(0)("ContainerName")
        dataEntity.ClientOtherValue = attributeDT.Rows(0)("Level")
        m_DataList.Add(dataEntity)

        Dim api As New CamstarClientAPI(serverHost.UserName, serverHost.Password)
        Dim maintDoc As String = "ContainerAttrMaintDoc"
        Dim maint As String = "ContainerAttrMaint"
        Dim listField As String = "ServiceDetails"
        AddExtendAttribute.IsError = Not api.RunTxnServiceHasSubentity(maintDoc, maint, m_DataList, listField, m_AttrList, strInfo)
        AddExtendAttribute.Message = strInfo
    End Function

    ''' <summary>
    ''' 根据订单ID获取批次列表
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetContainerListByMfgOrder(ByVal strMfgOrderID As String) As uMESProcessResult Implements IBusiness.uLMSContainerIBusiness.GetContainerListByMfgOrder
        GetContainerListByMfgOrder = New uMESProcessResult
        Dim sb As New StringBuilder
        sb.AppendLine("SELECT C.CONTAINERID,C.CONTAINERNAME,C.QTY,C.CONTAINERTYPE, C.TOGETHERFLAG, C.originalstartdate  ")
        sb.AppendLine("  FROM CONTAINER C")
        sb.AppendLine(" WHERE  C.PARENTCONTAINERID IS NULL AND C.STATUS <> 0 AND C.qualificationqty=1 ") 'add:wangjh qualificationqty=1排除子卡，热表卡
        sb.AppendFormat(" AND C.MFGORDERID = '{0}' ", strMfgOrderID)
        sb.AppendLine("ORDER BY C.CONTAINERID")
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(sb.ToString)

        If dt Is Nothing Then
            GetContainerListByMfgOrder.Result = False
            GetContainerListByMfgOrder.DBTable = New DataTable
        Else
            GetContainerListByMfgOrder.Result = True
            GetContainerListByMfgOrder.DBTable = dt
        End If
    End Function

    ''' <summary>
    ''' 批次移动
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerMoveStd(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal strEmployee As String, ByRef strMsg As String) As Boolean Implements uLMSContainerIBusiness.ContainerMoveStd
        ContainerMoveStd = False

        Dim strInfo As String = ""
        Dim strTxnDocName, strTxnName As String
        strTxnDocName = "MoveStdDoc"
        strTxnName = "MoveStd"

        Dim m_DataList As New List(Of ClientAPIEntity)
        Dim dataEntity As ClientAPIEntity
        dataEntity = New ClientAPIEntity("Container", InputTypeEnum.Details, DataTypeEnum.ContainerField, strContainerName, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("ReportEmployee", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, strEmployee, "")
        m_DataList.Add(dataEntity)

        Dim clientData As New CamstarClientAPI(host.UserName, host.Password)

        ContainerMoveStd = clientData.RunTxnService(strTxnDocName, strTxnName, m_DataList, strMsg)

    End Function


    ''' <summary>
    ''' 批次移动 重载 添加note移动标识 add tianFW 2018年4月12日
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerMoveStd(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal strEmployee As String, ByVal notes As String, ByRef strMsg As String) As Boolean Implements uLMSContainerIBusiness.ContainerMoveStd
        ContainerMoveStd = False

        Dim strInfo As String = ""
        Dim strTxnDocName, strTxnName As String
        strTxnDocName = "MoveStdDoc"
        strTxnName = "MoveStd"

        Dim m_DataList As New List(Of ClientAPIEntity)
        Dim dataEntity As ClientAPIEntity
        dataEntity = New ClientAPIEntity("Container", InputTypeEnum.Details, DataTypeEnum.ContainerField, strContainerName, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("ReportEmployee", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, strEmployee, "")
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity("Notes", InputTypeEnum.Details, DataTypeEnum.DataField, notes, "")
        m_DataList.Add(dataEntity)

        Dim clientData As New CamstarClientAPI(host.UserName, host.Password)

        ContainerMoveStd = clientData.RunTxnService(strTxnDocName, strTxnName, m_DataList, strMsg)

    End Function


    ''' <summary>
    ''' 批次非标移动
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerMoveNonStd(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal strWorkFlow As String, ByVal strWFVersion As String, ByVal strToStep As String, ByVal strEmployee As String, ByVal ToStepID As String, ByRef strMsg As String, Optional ByVal notes As String = "") As Boolean Implements uLMSContainerIBusiness.ContainerMoveNonStd
        ContainerMoveNonStd = False

        Dim strInfo As String = ""
        Dim strTxnDocName, strTxnName As String
        strTxnDocName = "MoveNonStdDoc"
        strTxnName = "MoveNonStd"

        Dim m_DataList As New List(Of ClientAPIEntity)
        Dim dataEntity As ClientAPIEntity

        dataEntity = New ClientAPIEntity("Container", InputTypeEnum.Details, DataTypeEnum.ContainerField, strContainerName, "")
        m_DataList.Add(dataEntity)
        dataEntity = New ClientAPIEntity("ToWorkflow", InputTypeEnum.Details, DataTypeEnum.RevisionedObjectField, strWorkFlow, strWFVersion)
        m_DataList.Add(dataEntity)
        dataEntity = New ClientAPIEntity("ToStep", InputTypeEnum.Details, DataTypeEnum.NamedSubentityField, strToStep, "")
        m_DataList.Add(dataEntity)
        dataEntity = New ClientAPIEntity("ReportEmployee", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, strEmployee, "")
        m_DataList.Add(dataEntity)
        '增加存入notes add:Wangjh 20180911
        dataEntity = New ClientAPIEntity("Notes", InputTypeEnum.Details, DataTypeEnum.DataField, notes, "")
        m_DataList.Add(dataEntity)
        '
        Dim clientData As New CamstarClientAPI(host.UserName, host.Password)
        ContainerMoveNonStd = clientData.RunTxnService(strTxnDocName, strTxnName, m_DataList, strMsg)

    End Function
    ''' <summary>
    ''' 报废批次数量
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks> 
    Public Function ScrapContainerQty(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal dtChildList As DataTable, ByRef strMsg As String) As Boolean Implements uLMSContainerIBusiness.ScrapContainerQty
        ScrapContainerQty = False

        Dim strTxnDocName, strTxnName As String
        strTxnDocName = "ChangeQtyDoc"
        strTxnName = "ChangeQty"

        Dim m_DataList As New List(Of ClientAPIEntity)
        Dim dataEntity As ClientAPIEntity

        Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))
        Dim clientData As New CamstarClientAPI(host.UserName, host.Password)
        Dim isChild As Boolean = False
        If dtChildList IsNot Nothing Then
            For Each row As DataRow In dtChildList.Rows
                Dim m_Child As New List(Of ClientAPIEntity)
                Dim stepEntity As ClientAPIEntity
                If Not row.IsNull("ChildContainer") Then
                    stepEntity = New ClientAPIEntity("Container", InputTypeEnum.Details, DataTypeEnum.ContainerField, row.Item("ChildContainer").ToString, "")
                    m_Child.Add(stepEntity)
                    m_DataList.Clear()
                    m_ChildList.Clear()
                    dataEntity = New ClientAPIEntity("CloseWhenZero", DataTypeEnum.DataField, True, "")
                    m_DataList.Add(dataEntity)
                    dataEntity = New ClientAPIEntity("Container", InputTypeEnum.Details, DataTypeEnum.ContainerField, row.Item("ChildContainer").ToString, "")
                    m_DataList.Add(dataEntity)
                    isChild = True
                End If
                stepEntity = New ClientAPIEntity("WorkerID", InputTypeEnum.Details, DataTypeEnum.DataField, row.Item("WorkerID").ToString, "")
                m_Child.Add(stepEntity)

                If dtChildList.Columns.Contains("ContainerStepWorkReportID") Then
                    stepEntity = New ClientAPIEntity("ContainerStepWorkReportID", InputTypeEnum.Details, DataTypeEnum.DataField, row.Item("ContainerStepWorkReportID").ToString, "")
                    m_Child.Add(stepEntity)
                End If

                stepEntity = New ClientAPIEntity("Qty", InputTypeEnum.Details, DataTypeEnum.DataField, row.Item("Qty").ToString, "")
                m_Child.Add(stepEntity)

                stepEntity = New ClientAPIEntity("ReasonCode", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, row.Item("ReasonCode").ToString, "")
                m_Child.Add(stepEntity)

                stepEntity = New ClientAPIEntity("CheckerID", InputTypeEnum.Details, DataTypeEnum.DataField, row.Item("CheckerID").ToString, "") 'add:Wangjh 2017-9-14 报废人
                m_Child.Add(stepEntity)

                stepEntity = New ClientAPIEntity("CheckDate", InputTypeEnum.Details, DataTypeEnum.DataField, Now.ToString("yyyy-MM-ddTHH:mm:ss"), "") 'add:Wangjh 2017-9-14 报废时间
                m_Child.Add(stepEntity)

                If isChild Then
                    m_ChildList.Add(0, m_Child)
                    ScrapContainerQty = clientData.ContainerChangeQty(strTxnDocName, strTxnName, m_DataList, "ServiceDetails", m_ChildList, "Loss", strMsg)

                Else
                    m_ChildList.Add(dtChildList.Rows.IndexOf(row), m_Child)
                End If
            Next
            '子序号情况，更改containercurrentinfo数据
            Dim strSql = "update containercurrentinfo set qty=qty-" + dtChildList.Rows.Count.ToString + " where containername='" + strContainerName + "'"
            DatabaseHelper.ExecuteSql(strSql)
        End If

        If Not isChild Then

            dataEntity = New ClientAPIEntity("CloseWhenZero", DataTypeEnum.DataField, True, "")
            m_DataList.Add(dataEntity)
            dataEntity = New ClientAPIEntity("Container", InputTypeEnum.Details, DataTypeEnum.ContainerField, strContainerName, "")
            m_DataList.Add(dataEntity)

            ScrapContainerQty = clientData.ContainerChangeQty(strTxnDocName, strTxnName, m_DataList, "ServiceDetails", m_ChildList, "Loss", strMsg)

        End If

    End Function

    ''' <summary>
    ''' 批次拆分
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function SplitContainer(ByVal para As ContainerSplitInfo) As ResultStatus Implements uLMSContainerIBusiness.SplitContainer
        Dim result As New ResultStatus
        Dim strContainerName As String = para.ContainerName

        '拆分批次
        Dim m_DataList As New List(Of ClientAPIEntity)

        Dim dataEntity As New ClientAPIEntity

        dataEntity.ClientDataName = "Container"
        dataEntity.ClientDataValue = strContainerName
        dataEntity.ClientOtherValue = "Lot"
        dataEntity.ClientDataTypeEnum = DataTypeEnum.ContainerField
        m_DataList.Add(dataEntity)

        Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))

        Dim ToInfoList As List(Of ToContainerInfo) = para.ToContainerInfo

        Dim m_Child As New List(Of ClientAPIEntity)
        For i As Integer = 0 To ToInfoList.Count - 1
            Dim childEntity As New ClientAPIEntity
            childEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            childEntity.ClientDataName = "ToContainerName"
            childEntity.ClientDataValue = ToInfoList(i).ToContainerName
            m_Child.Add(childEntity)

            childEntity = New ClientAPIEntity
            childEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            childEntity.ClientDataName = "Qty"
            childEntity.ClientDataValue = ToInfoList(i).Qty
            m_Child.Add(childEntity)

            m_ChildList.Add(i.ToString, m_Child)
        Next

        Dim dtChildList As DataTable = para.ChildContainer

        Dim strInfo As String = ""
        Dim serverUser As String = para.ServerHostInfo.UserName
        Dim serverPassword As String = para.ServerHostInfo.Password

        '创建批次结束
        Dim api As New CamstarClientAPI(serverUser, serverPassword)
        result.IsError = Not api.Split(m_DataList, m_ChildList, dtChildList, strInfo)
        result.Message = strInfo
        Return result
    End Function

    ''' <summary>
    ''' 获取批次历史数据 
    ''' </summary>
    ''' <param name="strContainerID"></param>
    ''' <returns></returns>
    ''' <remarks>修改 tianFW 2018年2月7日17</remarks>
    Public Function GetContainerHistoryData(ByVal strContainerID As String) As DataTable Implements IBusiness.uLMSContainerIBusiness.GetContainerHistoryData
        Dim sbCondition As New StringBuilder
        sbCondition.AppendLine("SELECT HML.TXNDATE,WFS.WORKFLOWSTEPNAME, HML.WORKFLOWSTEPID, HML.TXNTYPE,CDO.CDONAME,QS.QTYHISTORYID,") 'add QS.QTYHISTORYID,MH.REPORTEMPLOYEEID,EM.FULLNAME MOVER
        sbCondition.AppendLine("HML.CONTAINERID,QS.QTY CHANGEQTY,MH.REPORTEMPLOYEEID,EM.FULLNAME MOVER,MH.NOTES,HML.HISTORYMAINLINEID") 'del LRS.LOSSREASONNAME,QADS.QTYADJUSTREASONNAME
        sbCondition.AppendLine(",HML.HISTORYID")
        sbCondition.AppendLine("FROM HISTORYMAINLINE HML")
        sbCondition.AppendLine("LEFT JOIN CDODEFINITION CDO ON CDO.CDODEFID = HML.TXNTYPE")
        sbCondition.AppendLine("LEFT JOIN WORKFLOWSTEP WFS ON WFS.WORKFLOWSTEPID = HML.WORKFLOWSTEPID")
        sbCondition.AppendLine("LEFT JOIN QTYHISTORY QS ON QS.HISTORYMAINLINEID = HML.HISTORYMAINLINEID")
        'sbCondition.AppendLine("LEFT JOIN QTYHISTORYDETAILS QD ON QD.QTYHISTORYID = QS.QTYHISTORYID")
        sbCondition.AppendLine("LEFT JOIN MOVEHISTORY MH ON HML.HISTORYMAINLINEID = MH.HISTORYMAINLINEID")
        sbCondition.AppendLine("LEFT JOIN EMPLOYEE EM ON EM.EMPLOYEEID = MH.REPORTEMPLOYEEID")
        'sbCondition.AppendLine("LEFT JOIN LOSSREASON LRS ON LRS.LOSSREASONID = QD.REASONCODEID")
        'sbCondition.AppendLine("LEFT JOIN QTYADJUSTREASON QADS ON QADS.QTYADJUSTREASONID = QD.REASONCODEID")
        If strContainerID.EndsWith("type_3") Then
            sbCondition.AppendFormat("WHERE HML.REVERSALSTATUS = 1 AND HML.HISTORYID= '{0}' ORDER BY HML.HISTORYMAINLINEID DESC", strContainerID.Substring(0, strContainerID.Length - 6))
        ElseIf strContainerID.Contains(",") Then
            sbCondition.AppendFormat(" WHERE HML.REVERSALSTATUS = 1 AND HML.CONTAINERID IN ({0}) ORDER BY HML.HISTORYMAINLINEID DESC", strContainerID)
        Else
            sbCondition.AppendFormat(" WHERE HML.REVERSALSTATUS = 1 AND HML.CONTAINERID= '{0}' ORDER BY HML.HISTORYMAINLINEID DESC", strContainerID)
        End If
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(sbCondition.ToString)
        If dt Is Nothing Then
            GetContainerHistoryData = New DataTable
        Else
            dt.Columns.Add("CONTAINERSTEPWORKREPORTID") 'add tianFW 增加数量改变操作人查询以及报工ID查询 2018年2月7日
            dt.Columns.Add("CHECKERID")
            dt.Columns.Add("QTYCHANGEER")
            dt.Columns.Add("LOSSREASONNAME")
            dt.Columns.Add("QTYADJUSTREASONNAME")
            dt.Columns.Add("CONTAINERSTEPWORKREPORTIDANDLOSSQTY")
            Dim strsql As New StringBuilder
            For Each dr As DataRow In dt.Rows
                If Not dr.IsNull("QTYHISTORYID") Then
                    strsql.Clear()
                    strsql.AppendLine("SELECT QD.CONTAINERSTEPWORKREPORTID,QD.CHECKERID,EM.FULLNAME QTYCHANGEER,LRS.LOSSREASONNAME,QADS.QTYADJUSTREASONNAME,QD.QTY")
                    strsql.AppendLine("FROM QTYHISTORYDETAILS QD ")
                    strsql.AppendLine("LEFT JOIN EMPLOYEE EM ON EM.EMPLOYEEID = QD.CHECKERID")
                    strsql.AppendLine("LEFT JOIN LOSSREASON LRS ON LRS.LOSSREASONID = QD.REASONCODEID")
                    strsql.AppendLine("LEFT JOIN QTYADJUSTREASON QADS ON QADS.QTYADJUSTREASONID = QD.REASONCODEID")
                    strsql.AppendFormat(" WHERE QD.QTYHISTORYID='{0}'", dr("QTYHISTORYID"))
                    Dim dt_ As DataTable = DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
                    Dim workStepReportID As String = ""
                    Dim CheckerID As String = ""
                    Dim QtyChanger As String = ""
                    Dim LossReasonName As String = ""
                    Dim QtyAdjustReasonName As String = ""
                    Dim workStepReportIDAndQty As String = ""
                    For Each dr_ As DataRow In dt_.Rows
                        If Not dr_.IsNull("CONTAINERSTEPWORKREPORTID") Then
                            workStepReportID += "," & dr_("CONTAINERSTEPWORKREPORTID")
                            workStepReportIDAndQty += "," & dr_("CONTAINERSTEPWORKREPORTID") & "|" & dr_("QTY")
                        End If
                        If CheckerID = "" Then
                            CheckerID = dr_("CHECKERID").ToString()
                        ElseIf Not CheckerID.Contains(dr_("CHECKERID").ToString()) Then
                            CheckerID += "," & dr_("CHECKERID").ToString()
                        End If
                        If QtyChanger = "" Then
                            QtyChanger = dr_("QTYCHANGEER").ToString()
                        ElseIf Not QtyChanger.Contains(dr_("QTYCHANGEER").ToString()) Then
                            QtyChanger += "," & dr_("QTYCHANGEER").ToString()
                        End If
                        If LossReasonName = "" Then
                            LossReasonName = dr_("LOSSREASONNAME").ToString()
                        ElseIf Not LossReasonName.Contains(dr_("LOSSREASONNAME").ToString()) Then
                            LossReasonName += "," & dr_("LOSSREASONNAME").ToString()
                        End If
                        If QtyAdjustReasonName = "" Then
                            QtyAdjustReasonName = dr_("QTYADJUSTREASONNAME").ToString()
                        ElseIf Not QtyAdjustReasonName.Contains(dr_("QTYADJUSTREASONNAME").ToString()) Then
                            QtyAdjustReasonName += "," & dr_("QTYADJUSTREASONNAME").ToString()
                        End If
                    Next
                    If workStepReportIDAndQty <> "" Then
                        dr("CONTAINERSTEPWORKREPORTIDANDLOSSQTY") = workStepReportIDAndQty.Substring(1)
                    End If
                    If workStepReportID <> "" Then
                        dr("CONTAINERSTEPWORKREPORTID") = workStepReportID.Substring(1)
                    End If
                    If CheckerID <> "" Then
                        dr("CHECKERID") = CheckerID
                    End If
                    If QtyChanger <> "" Then
                        dr("QTYCHANGEER") = QtyChanger
                    End If
                    If LossReasonName <> "" Then
                        dr("LOSSREASONNAME") = LossReasonName
                    End If
                    If QtyAdjustReasonName <> "" Then
                        dr("QTYADJUSTREASONNAME") = QtyAdjustReasonName
                    End If
                End If
            Next
            GetContainerHistoryData = dt
        End If
    End Function

    Public Function GetContainerInfoData(ByVal strContainerName As String) As System.Data.DataTable Implements IBusiness.uLMSContainerIBusiness.GetContainerInfoData
        Dim sbCondition As New StringBuilder
        sbCondition.AppendLine(" SELECT * FROM CONTAINERCURRENTINFO")
        sbCondition.AppendFormat("   WHERE CONTAINERNAME= '{0}' ", strContainerName)
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(sbCondition.ToString)
        If dt Is Nothing Then
            GetContainerInfoData = New DataTable
        Else
            GetContainerInfoData = dt
        End If
    End Function

    ''' <summary>
    ''' 通过批次Name获取批次信息 add by tianFW 2018年12月18日
    ''' </summary>
    ''' <param name="strContainerName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetContainerInfoDataByName(ByVal strContainerName As String) As System.Data.DataTable Implements IBusiness.uLMSContainerIBusiness.GetContainerInfoDataByName
        Dim sbCondition As New StringBuilder
        sbCondition.AppendLine(" SELECT * FROM CONTAINERCURRENTINFO")
        sbCondition.AppendFormat("   WHERE UPPER(CONTAINERNAME) LIKE UPPER('%{0}%') ", strContainerName)
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(sbCondition.ToString)
        If dt Is Nothing Then
            GetContainerInfoDataByName = New DataTable
        Else
            GetContainerInfoDataByName = dt
        End If
    End Function

    ''' <summary>
    ''' 获取批次表信息数据
    ''' create：YangSJ 2017-12-8
    ''' Modify by Yuxj20180702 增加根据批次ID查询，装试扫描任务单批次ID返回任务单号使用
    ''' </summary>
    ''' <param name="strContainerName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetContainerData(ByVal strContainerName As String) As DataTable Implements IBusiness.uLMSContainerIBusiness.GetContainerData
        Dim sbCondition As New StringBuilder
        sbCondition.AppendLine(" SELECT * FROM CONTAINER")
        sbCondition.AppendFormat("   WHERE CONTAINERNAME= '{0}' ", strContainerName)
        'Modify by Yuxj21080702
        sbCondition.AppendFormat("   or CONTAINERID= '{0}' ", strContainerName)
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(sbCondition.ToString)
        If dt Is Nothing Then
            GetContainerData = New DataTable
        Else
            GetContainerData = dt
        End If
    End Function

#Region "调度平台"
    ''' <summary>
    ''' 获取批次当前信息（调度平台用)
    ''' create:Wangjh
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetCurrentContianerInfo(ByVal para As Dictionary(Of String, String)) As uMESProcessResult Implements uLMSContainerIBusiness.GetCurrentContianerInfo
        Dim strSelect As String = "SELECT  c.workflowid,c.productid,c.togetherflag,DECODE(C.CONTAINERTYPE,2,'批量加工',3,'批量带子序号', 7,'单件加工') AS CONTAINERTYPENAME,c.containertype,c.productname," &
                            "c.ProductDescription AS description,(c.workflowname||':'||c.workflowrevision) workflowname ,c.workflowrevision,c.workflowstepid,c.workflowstepname," &
                                "p.productrevision,cc.childcount,c.mfgordername,c.WORKFLOWROUTE,c.containerno"
        Dim strSql As StringBuilder = New StringBuilder
        strSql.AppendLine(strSelect)
        strSql.AppendLine(",SUM(C.QTY) AS QTY")
        strSql.AppendLine(" FROM containercurrentinfo c ")
        Dim joinSql As String = "LEFT JOIN container cc ON cc.containerid=c.containerid" & vbCrLf &
                                "LEFT JOIN product p ON p.productid=c.productid " & vbCrLf &
                                "left join workflow w on w.workflowid=c.workflowid"

        strSql.AppendLine(joinSql)
        strSql.AppendLine("where c.containerstatus<>0")
        strSql.AppendLine("and c.containertype=7")
        Dim sbCondition As String = QueryCondition(para)
        strSql.AppendLine(sbCondition)
        strSql.AppendLine("GROUP BY c.workflowid,c.productid,c.togetherflag,c.CONTAINERTYPE,")
        strSql.AppendLine("c.containertype, c.productname, c.ProductDescription, c.workflowname, c.workflowrevision,")
        strSql.AppendLine("c.workflowstepid, c.workflowstepname,  p.productrevision,cc.childcount,c.mfgordername,c.containerno,c.WORKFLOWROUTE")
        strSql.AppendLine("UNION")
        strSql.AppendLine(strSelect)
        strSql.AppendLine(",C.QTY")
        strSql.AppendLine("FROM containercurrentinfo c")
        strSql.AppendLine(joinSql)
        strSql.AppendLine("LEFT JOIN Userattribute ub ON ub.parentid=c.containerid  AND ub.userattributename='CheckTechnique' ")
        strSql.AppendLine("LEFT JOIN employee ee ON ee.employeename=ub.attributevalue or ee.fullname=ub.attributevalue ")
        strSql.AppendLine("where c.containerstatus<>0 ")
        strSql.AppendLine("and c.containertype<>7")
        strSql.AppendLine(sbCondition)
        strSql.AppendLine("GROUP BY  c.workflowid,c.productid,c.togetherflag,C.CONTAINERTYPE,c.productname,c.ProductDescription,c.workflowname,c.workflowrevision,c.workflowstepid,")
        strSql.AppendLine("c.workflowstepname,p.productrevision,cc.childcount,c.mfgordername,C.QTY,C.CONTAINERID,C.containername,ee.fullname,c.containerno,c.WORKFLOWROUTE")
        strSql.Insert(0, "select  nvl(aa.WORKFLOWROUTE,aa.productname)||'/'||aa.containerno ProductBatch,aa.productname||'/'||aa.containerno ProductBatchHidden,aa.* from (")
        strSql.AppendLine(") aa")
        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(para("CurrentPageIndex"))
        paraPage.PageSize = Convert.ToInt32(para("PageSize").ToString)
        paraPage.strSQL = strSql.ToString
        '主数据进行分页
        Dim result As uMESProcessResult = DatabaseHelper.RunProcedureForPage(paraPage)

        Dim containerflag As String = ""
        Dim tempDt As DataTable = result.DBTable.Copy
        If Not para.ContainsKey("NewGrid") Then
            '子表 单件单卡

            Dim dv As DataView = tempDt.DefaultView
            dv.RowFilter = "containertype='7'"

            For Each drv As DataRowView In dv
                containerflag += String.Format(" (c.togetherflag='{0}' AND C.PRODUCTID='{1}' AND C.WORKFLOWSTEPID='{2}'",
                                                drv("TOGETHERFLAG"), drv("PRODUCTID"), drv("WORKFLOWSTEPID"))
                If IsDBNull(drv("MFGORDERNAME")) Then
                    containerflag += String.Format(" AND C.MFGORDERNAME IS NULL) OR")
                Else
                    containerflag += String.Format(" AND C.MFGORDERNAME='{0}') OR", drv("MFGORDERNAME"))
                End If

            Next

            If containerflag.Length > 0 Then
                containerflag = containerflag.Substring(0, containerflag.Length - 2)
            End If

        End If

        Dim sonsql As New StringBuilder
        Dim sonSelect As String = "SELECT  c.qty,c.workflowid,c.productid,c.togetherflag,c.containertype,c.workflowstepid,c.containerid,c.containername," &
                                "c.mfgordername,ee.fullname CheckTechnique,Cc.STARTEMPLOYEEID,c.techniqueemployeeid,c.isinstore,c.ishold" 'add tianFW 2018年2月7日C.STARTEMPLOYEEID 'add c.techniqueemployeeid,c.isinstore 2018年7月11日
        sonsql.AppendLine(sonSelect)
        sonsql.AppendLine(" ,NVL(c.isdispatch,0) isdispatch,NVL(c.WORKREPORTNUM,0) WORKREPORTNUM")
        sonsql.AppendLine(" ,0 IsChecked")
        sonsql.AppendLine(" ,NVL(C.IsShip,0) IsShip")
        sonsql.AppendLine(" ,NVL(C.iscommissioning,0) iscommissioning")
        sonsql.AppendLine(" ,NVL(C.splitnum,0) IsSplit,NVL(C.nonconformingnum,0) NonconNum,nvl(sum(csd.qty),0) disQty")
        sonsql.AppendLine(" ,0 cheqty")
        sonsql.AppendLine("  FROM containercurrentinfo c")
        sonsql.AppendLine(joinSql)
        sonsql.AppendLine(" LEFT JOIN Userattribute ub ON ub.parentid=c.containerid  AND ub.userattributename='CheckTechnique'")
        sonsql.AppendLine(" LEFT JOIN employee ee ON ee.employeename=ub.attributevalue or ee.fullname=ub.attributevalue ")
        sonsql.AppendLine(" LEFT JOIN CONTAINERSTEPDISPATCH CSD ON CSD.CONTAINERID=C.CONTAINERID AND CSD.WORKFLOWSTEPID=C.WORKFLOWSTEPID AND CSD.ISUSE=0") '派工表
        sonsql.AppendLine(" where 1=1")
        If Not para.ContainsKey("NewGrid") Then
            sonsql.AppendFormat(" and c.containertype=7 ")
        End If

        If Not String.IsNullOrWhiteSpace(containerflag) Then
            sonsql.AppendLine(String.Format(" AND ({0})", containerflag))
        End If

        sonsql.AppendLine(sbCondition)
        If Not para.ContainsKey("NewGrid") Then
            sonsql.AppendLine(" GROUP BY c.qty,C.workflowid,c.productid,c.togetherflag,c.containertype,C.WORKFLOWSTEPID,c.containerid,c.containername,C.MFGORDERNAME,ee.fullname,")
            sonsql.AppendLine(" C.isdispatch,C.WORKREPORTNUM,C.IsShip,C.iscommissioning,C.splitnum,C.nonconformingnum,CC.STARTEMPLOYEEID,c.techniqueemployeeid,isinstore,w.process_No,c.ishold") 'add  c.techniqueemployeeid,isinstore by tianFW 2018年7月12日
            sonsql.AppendLine(" ORDER BY c.TOGETHERFLAG,c.containername")
        End If
        Dim sonContainerDt As New DataTable

        If containerflag.Length > 0 Then '存在单件单卡的时候才查询子表
            sonContainerDt = DatabaseHelper.Query_ReturnDatTable(sonsql.ToString())
        Else
            sonContainerDt = tempDt.Clone
        End If
        sonContainerDt.Columns.Add("FaContainerID")

        If para.ContainsKey("NewGrid") Then
            Dim sonSqlDt As DataTable = New DataTable
            sonSqlDt.Columns.Add("ChildContainerSql")
            sonSqlDt.Columns("ChildContainerSql").DefaultValue = sonsql.ToString
            sonSqlDt.Rows.Add()
            sonSqlDt.AcceptChanges()

            tempDt.Merge(sonSqlDt)
            tempDt.DefaultView.RowFilter = " ProductBatch is not null"
        End If


        Dim ds As New DataSet
        ds.Tables.Add(tempDt.DefaultView.ToTable.Copy())
        ds.Tables(0).TableName = "sumContainer"
        ds.Tables.Add(sonContainerDt)
        ds.Tables(1).TableName = "sonContainer"
        If containerflag.Length > 0 Then '存在单件单卡的时候才关联
            ds.Relations.Add("SumContainer",
            New DataColumn() {ds.Tables(0).Columns("FaContainerID"), ds.Tables(0).Columns("PRODUCTID"), ds.Tables(0).Columns("TOGETHERFLAG"),
                              ds.Tables(0).Columns("CONTAINERTYPE"), ds.Tables(0).Columns("WORKFLOWSTEPID"), ds.Tables(0).Columns("MFGORDERNAME")},
            New DataColumn() {ds.Tables(1).Columns("FaContainerID"), ds.Tables(1).Columns("PRODUCTID"), ds.Tables(1).Columns("TOGETHERFLAG"),
                              ds.Tables(1).Columns("CONTAINERTYPE"), ds.Tables(1).Columns("WORKFLOWSTEPID"), ds.Tables(1).Columns("MFGORDERNAME")})
        End If

        result.DBDataSet = ds
        Return result





    End Function
    ''' <summary>
    ''' 获取装饰批次当前信息（调度平台用)
    ''' create:Wangjh
    ''' 增加工艺名称，施工单显示
    ''' Modify by Yuxj20190228
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetZSCurrentContianerInfo(ByVal para As Dictionary(Of String, String)) As uMESProcessResult Implements uLMSContainerIBusiness.GetZSCurrentContianerInfo
        Dim strSql As String = <string>
        SELECT ep.workflowid,c.productid,c.togetherflag,c.containertype,c.productname,c.productdescription AS description,(wfb.workflowname||':'||wf.workflowrevision) workflowname,
        wf.workflowrevision,c.workflowstepid,c.workflowstepname,c.productrevision,c.mfgordername,c.workflowroute,c.containerno,SUM(c.qty) qty,ut.attributevalue motorno,ws.workflowstepname mainstage,ws.workflowstepid mainstageid,
        wf.description wfdesc  
        FROM enginepartplan ep
        LEFT JOIN Userattribute ut ON ut.parentid=ep.mfgorderid AND ut.userattributename='发动机'
        LEFT JOIN containercurrentinfo c ON  nvl(ep.containerid,ep.enginecontainerid)=c.containerid
        LEFT JOIN workflow wf ON ep.workflowid=wf.workflowid
        LEFT JOIN workflowbase wfb ON wf.workflowbaseid=wfb.workflowbaseid
        LEFT JOIN Workflowstep ws ON ws.workflowstepid=ep.workflowstepid
        WHERE c.containertype=7</string>.Value
        Dim sbCondition As String = QueryCondition(para)
        If para.Keys.Contains("MotorNo") = True Then '发动机号
            sbCondition += String.Format(" AND  ut.attributevalue LIKE '%{0}%'", para("MotorNo").ToString)
        End If
        If para.Keys.Contains("MainStage") = True Then '大阶段
            sbCondition += String.Format(" AND  ws.workflowstepname LIKE '%{0}%'", para("MainStage").ToString)
        End If
        If para.Keys.Contains("TaskNo") = True Then '任务单号
            sbCondition += String.Format(" AND  ep.containerno LIKE '%{0}%'", para("TaskNo").ToString)
        End If
        strSql += sbCondition
        strSql += <string>
        GROUP BY ep.workflowid,c.productid,c.togetherflag,c.containertype,c.productname,c.productdescription,(wfb.workflowname||':'||wf.workflowrevision),
        wf.workflowrevision,c.workflowstepid,c.workflowstepname,c.productrevision,c.mfgordername,c.workflowroute,c.containerno,
        c.qty,ut.attributevalue ,ws.workflowstepname ,ws.workflowstepid,wf.description</string>.Value
        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(para("CurrentPageIndex"))
        paraPage.PageSize = Convert.ToInt32(para("PageSize").ToString)
        paraPage.strSQL = strSql.ToString
        '主数据进行分页
        Return DatabaseHelper.RunProcedureForPage(paraPage)

    End Function

    ''' <summary>
    ''' 查询单件单卡子卡的所需信息(调度用)
    ''' add:Wangjh 20180827
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetChildContainerNo(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSContainerIBusiness.GetChildContainerNo
        para("ChildContainerSql") += String.Format(" and((C.CONTAINERTYPE=7 AND C.TOGETHERFLAG='{0}' AND C.PRODUCTID='{1}' AND C.WORKFLOWSTEPID='{2}' AND C.MFGORDERNAME='{3}') OR (C.CONTAINERTYPE<>7 AND C.CONTAINERNAME='{4}') )",
                                                   para("TogatherFlag"), para("ProductID"), para("WorkflowStepID"), para("MfgOrderName"), para("ProductBatchHidden"))
        para("ChildContainerSql") += " GROUP BY c.qty,C.workflowid,c.productid,c.togetherflag,c.containertype,C.WORKFLOWSTEPID,c.containerid,c.containername,C.MFGORDERNAME,ee.fullname,"
        para("ChildContainerSql") += " C.isdispatch,C.WORKREPORTNUM,C.IsShip,C.iscommissioning,C.splitnum,C.nonconformingnum,CC.STARTEMPLOYEEID,c.techniqueemployeeid,isinstore,c.ishold"
        para("ChildContainerSql") += " ORDER BY c.TOGETHERFLAG,c.containername"
        Dim dt = DatabaseHelper.Query_ReturnDatTable(para("ChildContainerSql"))
        For Each row As DataRow In dt.Rows
            Dim strSql As String = <string>SELECT (CASE WHEN cfci.containerid is null and ccin.containerid is null THEN '0' ELSE '1' END) ischecked,nvl(cfci.containerid,ccin.containerid) containerid,
        nvl(cfci.workflowstepid,ccin.workflowstepid) workflowstepid,NVL(cfci.checkqty,sum(distinct ccin.checkqty)) cheqty FROM containerstepworkreport csw
        LEFT JOIN  containerfinishedcheckinfo cfci ON cfci.containerid=csw.containerid AND cfci.workflowstepid=csw.workflowstepid AND cfci.isuse=0
        LEFT JOIN containercheckinfo ccin ON ccin.containerid=csw.containerid AND ccin.workflowstepid=csw.workflowstepid AND ccin.isuse=0
        WHERE CSW.ISUSE = 0</string>.Value
            strSql += String.Format(" AND csw.containerid='{0}' AND csw.workflowstepid='{1}' ", row("containerid"), para("WorkflowStepID"))
            strSql += <string>GROUP BY cfci.containerid,ccin.containerid,cfci.workflowstepid,ccin.workflowstepid,cfci.checkqty</string>.Value
            Dim _dt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql)
            If _dt.Rows.Count > 0 Then
                row("ischecked") = _dt.Rows(0)("ischecked")
                row("cheqty") = _dt.Rows(0)("cheqty")
            End If
        Next
        dt.AcceptChanges()
        Return dt
    End Function

    ''' <summary>
    ''' 查询装试单件单卡子卡的所需信息(调度用)
    ''' add:Wangjh 20180827
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetZSChildContainerNo(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSContainerIBusiness.GetZSChildContainerNo
        Dim strSql As String = <string>SELECT ep.containerno taskno,cci.*  FROM enginepartplan ep 
        LEFT JOIN containercurrentinfo cci ON nvl(ep.containerid,ep.enginecontainerid)=cci.containerid WHERE cci.containertype=7 AND cci.containerstatus=1
                               </string>.Value
        strSql += String.Format(" AND cci.togetherflag='{0}' AND cci.productid='{1}' AND cci.mfgordername='{2}' and ep.workflowid='{3}'",
                                para("TogatherFlag"), para("ProductID"), para("MfgOrderName"), para("WorkflowID"))
        If String.IsNullOrEmpty(para("MainStageID")) Then
            strSql += " AND ep.workflowstepid is null"
        Else
            strSql += String.Format(" AND ep.workflowstepid='{0}'", para("MainStageID"))
        End If
        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    '''批次关闭
    ''' create:Wangjh 2017-9-6
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerClosed(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal strCloseReason As String, ByVal strNotes As String, ByRef strMsg As String) As Boolean Implements uLMSContainerIBusiness.ContainerClosed
        ContainerClosed = False
        Dim strInfo As String = ""
        Dim strTxnDocName, strTxnName As String
        strTxnDocName = "CloseDoc"
        strTxnName = "Close"

        Dim dataEntityList As New List(Of ClientAPIEntity)
        Dim dataEntity As New ClientAPIEntity
        dataEntityList.Clear()

        dataEntity = New ClientAPIEntity
        dataEntity.ClientDataName = "Container"
        dataEntity.ClientDataValue = strContainerName
        dataEntity.ClientDataTypeEnum = DataTypeEnum.ContainerField
        dataEntity.ClientOtherValue = "Lot"
        '  dataEntity.ClientDataValue=
        dataEntityList.Add(dataEntity)

        dataEntity = New ClientAPIEntity
        dataEntity.ClientDataName = "ChangeStatusReason"
        dataEntity.ClientDataValue = strCloseReason
        dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
        dataEntityList.Add(dataEntity)
        dataEntity = New ClientAPIEntity("Comments", InputTypeEnum.Details, DataTypeEnum.DataField, strNotes, "")
        dataEntityList.Add(dataEntity)
        Dim clientData As New CamstarClientAPI(host.UserName, host.Password)
        ContainerClosed = clientData.RunTxnService(strTxnDocName, strTxnName, dataEntityList, strMsg)
        If ContainerClosed = True Then '更改总表批次
            Dim updatePara As New Dictionary(Of String, String)
            Dim conditionPara As New Dictionary(Of String, String)
            conditionPara("ContainerName") = "'" + strContainerName + "'"
            updatePara("ContainerSTATUS") = 2
            m_ConCurrentinfoObj.UpdateContainerCurrentInfoByField(updatePara, conditionPara)
        End If
    End Function
    ''' <summary>
    ''' 批次打开
    ''' create:Wangjh
    ''' </summary>
    ''' <param name="host"></param>
    ''' <param name="strContainerName"></param>
    ''' <param name="strOpenReason"></param>
    ''' <param name="strMsg"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerOpen(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal strOpenReason As String, ByRef strMsg As String) As Boolean Implements uLMSContainerIBusiness.ContainerOpen
        Dim dataEntityList As New List(Of ClientAPIEntity)
        Dim dataEntity As New ClientAPIEntity
        dataEntityList.Clear()
        dataEntity = New ClientAPIEntity
        dataEntity.ClientDataName = "Container"
        dataEntity.ClientDataValue = strContainerName
        dataEntity.ClientDataTypeEnum = DataTypeEnum.ContainerField
        dataEntity.ClientOtherValue = "Lot"
        dataEntityList.Add(dataEntity)

        dataEntity = New ClientAPIEntity
        dataEntity.ClientDataName = "IncludeChildren"
        dataEntity.ClientDataValue = False
        dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
        dataEntityList.Add(dataEntity)

        dataEntity = New ClientAPIEntity
        dataEntity.ClientDataName = "ChangeStatusReason"
        dataEntity.ClientDataValue = strOpenReason
        dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
        dataEntityList.Add(dataEntity)

        Dim clientData As New CamstarClientAPI(host.UserName, host.Password)
        ContainerOpen = clientData.RunTxnService("OPenDoc", "Open", dataEntityList, strMsg)
        If ContainerOpen = True Then
            Dim updatePara As New Dictionary(Of String, String)
            Dim conditionPara As New Dictionary(Of String, String)
            conditionPara("ContainerName") = "'" + strContainerName + "'"
            updatePara("ContainerSTATUS") = 1
            m_ConCurrentinfoObj.UpdateContainerCurrentInfoByField(updatePara, conditionPara)
        End If
    End Function
    ''' <summary>
    ''' 批次数量修改
    ''' create:Wangjh 2017-9-7
    ''' </summary>
    ''' <param name="host"></param>
    ''' <param name="strContainerName"></param>
    ''' <param name="changeQry"></param>
    ''' <param name="strChangeReason"></param>
    ''' <param name="strMsg"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerChangeQty(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal changeQry As Integer, ByVal strChangeReason As String, ByRef strMsg As String) As Boolean Implements uLMSContainerIBusiness.ContainerChangeQty
        Dim m_DataList As New List(Of ClientAPIEntity)
        Dim dataEntity As New ClientAPIEntity
        m_DataList.Clear()
        dataEntity.ClientDataName = "Container"
        dataEntity.ClientDataValue = strContainerName
        dataEntity.ClientOtherValue = "Lot"
        dataEntity.ClientDataTypeEnum = DataTypeEnum.ContainerField
        m_DataList.Add(dataEntity)

        dataEntity = New ClientAPIEntity
        dataEntity.ClientDataName = "CloseWhenZero"
        dataEntity.ClientDataValue = False
        dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
        m_DataList.Add(dataEntity)

        Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))
        Dim m_Child As New List(Of ClientAPIEntity)
        Dim childEntity As New ClientAPIEntity

        childEntity.ClientDataTypeEnum = DataTypeEnum.DataField
        childEntity.ClientDataName = "Qty"
        childEntity.ClientDataValue = changeQry
        m_Child.Add(childEntity)

        childEntity = New ClientAPIEntity
        childEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
        childEntity.ClientDataName = "ReasonCode"
        childEntity.ClientDataValue = strChangeReason
        m_Child.Add(childEntity)
        m_ChildList.Add(0, m_Child)
        Dim api As New CamstarClientAPI(host.UserName, host.Password)
        ContainerChangeQty = api.ContainerChangeQty("ChangeQtyDoc", "ChangeQty", m_DataList, "ServiceDetails", m_ChildList, "Adjust", strMsg)

    End Function
    ''' <summary>
    ''' 根据containerID更改批次类型(单件单卡改批量)
    ''' </summary>
    ''' <param name="containerid"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ChangeContainerType(ByVal containerid As String, ByVal type As Integer) As Boolean Implements uLMSContainerIBusiness.ChangeContainerType
        Dim strSql As String = String.Format(" UPDATE container c SET c.containertype={0},c.togetherflag=c.containername WHERE c.containerid='{1}'", type, containerid)
        '更新总表一些信息
        Dim updatePara As New Dictionary(Of String, String)
        Dim conditionPara As New Dictionary(Of String, String)
        conditionPara("ContainerID") = "'" + containerid + "'"
        updatePara("togetherflag") = "containername"
        updatePara("containerno") = "SUBSTR(containername,INSTR(containername,productname)+length(productname||'/'))"
        updatePara("containertype") = type
        m_ConCurrentinfoObj.UpdateContainerCurrentInfoByField(updatePara, conditionPara)
        '
        Dim i As Integer = DatabaseHelper.ExecuteSql(strSql)
        If i > 0 Then
            ChangeContainerType = True
        Else
            ChangeContainerType = False
        End If
    End Function
    ''' <summary>
    ''' 删除流水卡
    ''' create:Wangjh 2017-9-7
    ''' </summary>
    ''' <param name="containers"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateDelContainer(ByVal containers As String) As Boolean Implements uLMSContainerIBusiness.UpdateDelContainer
        UpdateDelContainer = False
        Dim sqls As New ArrayList
        Dim sb As New StringBuilder
        '删除主子映射信息
        sqls.Add(String.Format("update containersubcontainer cc set cc.isuse=1 where cc.subcontainerid in (select containerid from container where containername in ({0}))", containers))
        'sqls.Add(String.Format("update containersubcontainer cc set cc.isuse=1 where cc.containerid in (select containerid from container where containername in ({0}))", containers)) 暂时不处理此情况
        '
        sb.AppendFormat("update container c set c.containername=c.containerid,c.status=0 where c.parentcontainerid in (select containerid from container where containername in ({0}))", containers)
        sqls.Add(sb.ToString())
        sb.Clear()
        sb.AppendFormat(" update container c set c.containername=c.containerid,c.status=0 where c.containername in ({0})", containers)
        sqls.Add(sb.ToString())
        '删除分批出来的批次记录 add:Wangjh 2023-1-11
        sqls.Add(String.Format("update containersplitinfo set isuse=1 where splitcontainername in ({0}) and splitresult=0 and isuse=0", containers))
        
        DatabaseHelper.ExecuteSqlTran(sqls)
        UpdateDelContainer = True
    End Function
    ''' <summary>
    ''' 根据containerID更新工艺员
    '''  create:Wangjh 2017-9-7
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEngineerNameOfContainer(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.UpdateEngineerNameOfContainer
        Dim strSql As String = String.Format("UPDATE Userattribute u SET u.attributevalue='{0}' WHERE u.parentid='{1}' AND u.userattributename='CheckTechnique'", para("FullName"), para("ContainerID"))
        UpdateEngineerNameOfContainer = DatabaseHelper.ExecuteSql(strSql)
    End Function
    ''' <summary>
    ''' 根据父containerID查询关闭的子批次 
    ''' create:Wangjh 2017-9-13
    ''' </summary>
    ''' <param name="containerID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetChildContainerInfo(ByVal containerID As String) As DataTable Implements uLMSContainerIBusiness.GetChildContainerInfo
        Dim strSql As String = String.Format("SELECT * FROM container c WHERE c.parentcontainerid='{0}' AND c.qty=1", containerID)
        GetChildContainerInfo = DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 增加批次删除记录 create by tianFW 2018年7月13日
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function AddDeleteContainerRecord(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.AddDeleteContainerRecord
        Dim strsql As String =
            <string>
                INSERT INTO OperContainerRecord(containerid,containername,productid,productname,operatorid,operreason,qty,createdate,opertype)
                VALUES(:containerid,:containername,:productid,:productname,:operatorid,:operreason,:qty,SYSDATE,:opertype)
            </string>
        Dim insertpara(7) As OracleParameter
        insertpara(0) = DatabaseHelper.NewParameter(":containerid", para("containerid"), OracleType.VarChar)
        insertpara(1) = DatabaseHelper.NewParameter(":containername", para("containername"), OracleType.VarChar)
        insertpara(2) = DatabaseHelper.NewParameter(":productid", para("productid"), OracleType.VarChar)
        insertpara(3) = DatabaseHelper.NewParameter(":productname", para("productname"), OracleType.VarChar)
        insertpara(4) = DatabaseHelper.NewParameter(":operatorid", para("operatorid"), OracleType.VarChar)
        insertpara(5) = DatabaseHelper.NewParameter(":operreason", para("operreason"), OracleType.VarChar)
        insertpara(6) = DatabaseHelper.NewParameter(":qty", para("qty"), OracleType.Number)
        insertpara(7) = DatabaseHelper.NewParameter(":opertype", para("opertype"), OracleType.VarChar)
        If DatabaseHelper.ExecuteSql(strsql, insertpara) > 0 Then
            '删除总表
            If para("opertype") = "1" Then
                DatabaseHelper.ExecuteSql("DELETE containercurrentinfo cci WHERE cci.containerid='" + para("containerid") + "'")
            End If
            '
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 查询批次工艺有派工未完的加工记录
    ''' add:Wangjh 20180720
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetStepProcessRecord(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSContainerIBusiness.GetStepProcessRecord
        Dim strSql As String = <string>
                                   SELECT csr.containerid FROM containersteprecord csr
                                    LEFT JOIN containerstepdispatch csd ON csd.containerstepdispatchid=csr.dispatchid
                                    WHERE csd.isuse=0 and csr.usecompleted=0
                               </string>
        If para.ContainsKey("ContainerID") Then
            strSql += " and csr.containerid='" + para("ContainerID") + "'"
        End If
        If para.ContainsKey("WorkFlowID") Then
            strSql += " AND csr.workflowid='" + para("WorkFlowID") + "'"
        End If
        strSql += "group by csr.containerid having sum(csr.dispatchqty)>sum(NVL(csr.reportqty,0))"
        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 装试调度或删除批次后需要更改一些东西
    ''' add:Wangjh 20181109
    ''' Modify by Yuxj20190326 将完工工序标记为空 en.completestepid=null,集件确认及报废数据可考虑在服务中删除
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteOrUpdateSomeAfterDeleteOrUpdateContainer(ByVal para As Dictionary(Of String, String)) As String Implements uLMSContainerIBusiness.DeleteOrUpdateSomeAfterDeleteOrUpdateContainer
        Dim strSql = ""
        Dim strInfo = ""
        If para("ZSType") = "0" Then '装试批次调度
            strSql = String.Format("UPDATE enginepartplan en SET en.workflowid='{0}',en.ISUPDATE = 0,en.completestepid=null,en.workflowstepcount=0,en.stepdispatchcount=0 WHERE en.containerid='{1}'", para("WorkflowID"), para("ContainerID"))
            If DatabaseHelper.ExecuteSql(strSql) > 0 Then
                strInfo += "已更新批次分解计划工艺"
            End If
            If para.ContainsKey("TaskNo") Then
                strSql = String.Format("DELETE partmenuinfo pi WHERE pi.containerno='{0}'", para("TaskNo"))
                If DatabaseHelper.ExecuteSql(strSql) > 0 Then
                    strInfo += "已删除零件目录表"
                End If
                strSql = String.Format("DELETE  FROM issueerpmaterial em WHERE em.containerno ='{0}'", para("TaskNo"))
                If DatabaseHelper.ExecuteSql(strSql) > 0 Then
                    strInfo += "已删除装配信息表"
                End If
            End If
        ElseIf para("ZSType") = "1" Then '装试批次删除
            Dim strmfgid As String = ""
            Dim dt As New DataTable
            If para.ContainsKey("ContainerNames") Then
                strSql = String.Format(" select mfgorderid FROM enginepartplan ep WHERE ep.ContainerName in ({0})", para("ContainerNames"))
                dt = DatabaseHelper.Query_ReturnDatTable(strSql)
                strmfgid = dt.Rows(0)("mfgorderid")
                '删除批次分解计划表
                strSql = String.Format(" DELETE FROM enginepartplan ep WHERE ep.ContainerName in ({0})", para("ContainerNames"))
                If DatabaseHelper.ExecuteSql(strSql) > 0 Then
                    strInfo += "已删除批次分解计划表"
                End If
                '
                '装配信息表
                strSql = String.Format("DELETE  FROM issueerpmaterial em WHERE em.containerid IN (SELECT c.containerid FROM container c WHERE c.containername IN ({0}))",
                 para("ContainerNames"))
                If DatabaseHelper.ExecuteSql(strSql) > 0 Then
                    strInfo += "已删除装配信息表"
                End If
                '
                If strmfgid <> "" Then
                    strSql = String.Format(" select * FROM enginepartplan ep WHERE ep.mfgorderid ='{0}' and ep.containerno is not null and type=1 ", strmfgid)
                    dt = DatabaseHelper.Query_ReturnDatTable(strSql)
                    If dt.Rows.Count = 0 Then
                        'yuxj20221201没有包含批次的订单，可能任务单全删除了，只剩下大阶段记录，执行删除
                        strSql = String.Format(" DELETE FROM enginepartplan ep WHERE ep.mfgorderid ='{0}' and type=1 ", strmfgid)
                        DatabaseHelper.ExecuteSql(strSql)
                    End If
                End If
            ElseIf para.ContainsKey("TaskNo") Then
                '零件目录表 
                strSql = String.Format("select * FROM enginepartplan ep WHERE ep.containerno ='{0}'", para("TaskNo"))
                dt = DatabaseHelper.Query_ReturnDatTable(strSql)
                If dt.Rows.Count = 0 Then
                    strSql = String.Format("DELETE partmenuinfo pi WHERE pi.containerno='{0}'", para("TaskNo"))
                    If DatabaseHelper.ExecuteSql(strSql) > 0 Then
                        strInfo += "已删除零件目录表"
                    End If
                Else
                    strmfgid = dt.Rows(0)("mfgorderid")
                End If
                '
            End If

        End If
        Return strInfo
    End Function

#End Region

    ''' <summary>
    ''' 查询条件
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function QueryCondition(ByVal para As Dictionary(Of String, String)) As String
        Dim strSql As String = ""
        If para.Keys.Contains("ContainerName") = True Then
            strSql += String.Format(" AND  LOWER(c.containername) LIKE LOWER('%{0}%')", para("ContainerName").ToString)
        End If
        If para.Keys.Contains("MfgOrderName") = True Then
            strSql += String.Format(" AND  LOWER(c.MfgOrderName) like LOWER('%{0}%')", para("MfgOrderName").ToString.ToLower)
        End If
        If para.Keys.Contains("ProductName") = True Then
            strSql += String.Format(" AND  LOWER(c.productname) LIKE LOWER('%{0}%')", para("ProductName").ToString)
        End If
        If para.Keys.Contains("FactoryID") = True Then
            strSql += " AND c.originalfactoryid= '" & para("FactoryID").ToString() & "' " & vbCrLf
        End If
        If para.Keys.Contains("Status") = True Then
            strSql += para("Status").ToString & vbCrLf
        End If
        If para.Keys.Contains("SpecNo") = True Then
            strSql += String.Format(" AND c.specno like '%{0}%'", para("SpecNo").ToString.ToLower)
        End If
        If para.ContainsKey("IsPause") Then
            If Not String.IsNullOrWhiteSpace(para("IsPause")) Then
                strSql += String.Format(" and c.ishold='{0}' ", para("IsPause"))
            End If
        End If
        QueryCondition = strSql
    End Function

    ''' <summary>
    ''' 查询批次move情况 create:Wangjh 2017-9-26
    ''' </summary>
    ''' <param name="containerID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetContainerMoveInfo(ByVal containerID As String) As DataTable Implements uLMSContainerIBusiness.GetContainerMoveInfo
        Dim strSql As String = " SELECT mh.movehistoryid FROM Movehistory mh" &
                                " INNER JOIN historymainline hsm ON hsm.historymainlineid=mh.historymainlineid"

        strSql += String.Format(" where hsm.containerid='{0}'", containerID)

        GetContainerMoveInfo = DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 插入子工艺校对信息
    ''' create：Wangjh 20171212
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function InsertSubWorkFlowCheckInfo(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.InsertSubWorkFlowCheckInfo
        Dim insertSql As String = <string>
                                  INSERT INTO SUBWORKFLOWCHECKINFO  SWC (SWC.CONTAINERID,SWC.CHECKTECHNIQUEID,SWC.SUBWORKFLOWID,SWC.SUBWORKFLOWCHECKINFOID,SWC.Checkresult,SWC.Createdate,SWC.WORKFLOWID,SWC.Workflowstepid)
                                  VALUES (:CONTAINERID,:CHECKTECHNIQUEID,:SUBWORKFLOWID,:SUBWORKFLOWCHECKINFOID,0,SYSDATE,:WORKFLOWID,:Workflowstepid)
                              </string>
        Dim insertPara(5) As OracleParameter
        insertPara(0) = DatabaseHelper.NewParameter(":containerid", para("ContainerID"), OracleType.VarChar)
        insertPara(1) = DatabaseHelper.NewParameter(":CHECKTECHNIQUEID", para("CheckTechniqueID"), OracleType.VarChar)
        insertPara(2) = DatabaseHelper.NewParameter(":SUBWORKFLOWID", para("SubWorkFlowID"), OracleType.VarChar)
        insertPara(3) = DatabaseHelper.NewParameter(":SUBWORKFLOWCHECKINFOID", Guid.NewGuid().ToString, OracleType.VarChar)
        insertPara(4) = DatabaseHelper.NewParameter(":WorkFlowID", para("WorkFlowID"), OracleType.VarChar)
        insertPara(5) = DatabaseHelper.NewParameter(":Workflowstepid", para("WorkFlowStepID"), OracleType.VarChar)
        Dim i As Integer = DatabaseHelper.ExecuteSql(insertSql, insertPara)

        If i > 0 Then
            InsertSubWorkFlowCheckInfo = True
        Else
            InsertSubWorkFlowCheckInfo = False
        End If

    End Function

    ''' <summary>
    ''' 删除子工艺校对信息 create tianFW 2018年1月25日
    ''' </summary>
    ''' <param name="ContainerID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DelSubWorkFlowCheckInfo(ByVal ContainerID As String) As Boolean Implements uLMSContainerIBusiness.DelSubWorkFlowCheckInfo
        Dim strsql As String = String.Format("DELETE FROM SUBWORKFLOWCHECKINFO SFI WHERE SFI.CONTAINERID='{0}'", ContainerID)
        If DatabaseHelper.ExecuteSql(strsql) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 获取非本分厂存在子工艺的批次
    ''' create:Wangjh 20171213
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetContainerOfSubWorkflowWithoutSelf(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSContainerIBusiness.GetContainerOfSubWorkflowWithoutSelf
        Dim strSql As String = <string>
                                SELECT c.containername,c.containerid FROM SubWorkflowCheckInfo swc
                                LEFT JOIN containercurrentinfo c ON c.containerid=swc.containerid
                                LEFT JOIN Workflow w ON w.workflowid=swc.subworkflowid
                                LEFT JOIN product p ON p.productid=c.productid
                                LEFT JOIN productbase pb ON pb.productbaseid=p.productbaseid
                                WHERE C.Containerstatus=1 AND swc.checkresult=0 and c.isinstore!=1
                               </string>
        strSql += String.Format(" AND w.factoryid='{0}'", para("FactoryID"))
        If para.ContainsKey("ContainerName") Then
            strSql += String.Format(" AND c.containername like '{0}%'", para("ContainerName"))
        End If
        If para.ContainsKey("ProductName") Then
            strSql += String.Format(" AND pb.productname like '%{0}%'", para("ProductName"))
        End If
        strSql += " GROUP BY c.containername,c.containerid"
        GetContainerOfSubWorkflowWithoutSelf = DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 根据批次获取所有子工艺信息
    ''' create:Wangjh 20171213
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetSubWorkFlowInfoByContainer(ByVal para As Dictionary(Of String, String)) As DataSet Implements uLMSContainerIBusiness.GetSubWorkFlowInfoByContainer
        Dim strSql As String = <string>
                                 SELECT m.mfgorderid,m.mfgordername,DECODE(c.containertype,7,NULL,c.containername) containername,c.togetherflag,
                                DECODE(c.containertype,7,NULL,c.containerid) containerid,wb.workflowname,w.workflowid,e.fullname,
                                DECODE(c.containertype,7,NULL,swc.subworkflowcheckinfoid) subworkflowcheckinfoid,fa.factoryname,w.factoryid,c.containertype,
                                ws.workflowstepname,pb.productname,p.productid,ws.workflowstepid,faws.workflowstepname faworkflowstepname,e2.fullname planemployeename  FROM SubWorkflowCheckInfo swc
                                LEFT JOIN container c ON c.containerid=swc.containerid
                                LEFT JOIN mfgorder m ON m.mfgorderid=c.mfgorderid
                                LEFT JOIN Currentstatus cu ON cu.currentstatusid=c.currentstatusid
                                LEFT JOIN workflowstep ws ON ws.workflowstepid=cu.workflowstepid
                                LEFT JOIN workflow w2 ON w2.workflowid=ws.workflowid--当前工艺
                                LEFT JOIN Workflow w ON w.workflowid=swc.subworkflowid--子工艺
                                LEFT JOIN factory fa ON fa.factoryid=w.factoryid
                                LEFT JOIN Workflowbase wb ON wb.workflowbaseid=w.workflowbaseid
                                LEFT JOIN product p ON p.productid=c.productid
                                LEFT JOIN productbase pb ON pb.productbaseid=p.productbaseid
                                LEFT JOIN employee e ON e.employeeid=swc.checktechniqueid
                                left join employee e2 on e2.employeeid=swc.planemployeeid
                                LEFT JOIN cdodefinition cdo ON cdo.cdodefid=w2.cdotypeid
                                left join workflowstep faws on faws.workflowstepid=swc.workflowstepid
                                WHERE c.status=1 and cdo.cdoname='Workflow' AND c.parentcontainerid IS NULL AND swc.checkresult=0
                             </string>
        strSql += String.Format(" and c.containerid IN ({0}) AND W.factoryid='{1}'", para("ContainerIDs"), para("FactoryID"))
        strSql += "GROUP BY m.mfgorderid,m.mfgordername,DECODE(c.containertype,7,NULL,c.containername),c.togetherflag," &
                 " DECODE(c.containertype,7,NULL,c.containerid),wb.workflowname,w.workflowid,e.fullname," &
                " DECODE(c.containertype,7,NULL,swc.subworkflowcheckinfoid),fa.factoryname,w.factoryid,c.containertype,ws.workflowstepname,pb.productname,p.productid,ws.workflowstepid,faws.workflowstepname,e2.fullname "
        strSql += " ORDER BY C.TOGETHERFLAG asc, DECODE(c.containertype,7,NULL,c.containername) ASC"
        Dim sumDt = DatabaseHelper.Query_ReturnDatTable(strSql)
        '子表 单件单卡
        Dim tempDt As DataTable = sumDt.Copy
        Dim dv As DataView = tempDt.DefaultView
        dv.RowFilter = "containertype='7'"
        Dim containerflag As String = ""
        For Each drv As DataRowView In dv
            containerflag += String.Format(" (c.togetherflag='{0}' AND P.PRODUCTID='{1}' AND WS.WORKFLOWSTEPID='{2}'",
                                            drv("TOGETHERFLAG"), drv("PRODUCTID"), drv("WORKFLOWSTEPID"))
            If IsDBNull(drv("MFGORDERNAME")) Then
                containerflag += String.Format(" AND M.MFGORDERNAME IS NULL) OR")
            Else
                containerflag += String.Format(" AND M.MFGORDERNAME='{0}') OR", drv("MFGORDERNAME"))
            End If
        Next

        If containerflag.Length > 0 Then
            containerflag = containerflag.Substring(0, containerflag.Length - 2)
        End If

        Dim sonsql As New StringBuilder
        sonsql.AppendLine("SELECT c.containerid,c.containername,swc.subworkflowcheckinfoid,P.PRODUCTID,C.TOGETHERFLAG,w.factoryid,C.CONTAINERTYPE,WS.WORKFLOWSTEPID,M.MFGORDERNAME,SWC.SUBWORKFLOWID workflowid")
        sonsql.AppendLine("FROM SubWorkflowCheckInfo swc")
        sonsql.AppendLine("LEFT JOIN container c ON c.containerid=swc.containerid")
        sonsql.AppendLine("LEFT JOIN mfgorder m ON m.mfgorderid=c.mfgorderid")
        sonsql.AppendLine("LEFT JOIN Currentstatus cu ON cu.currentstatusid=c.currentstatusid")
        sonsql.AppendLine("LEFT JOIN workflowstep ws ON ws.workflowstepid=cu.workflowstepid")
        sonsql.AppendLine("LEFT JOIN workflow w2 ON w2.workflowid=ws.workflowid")
        sonsql.AppendLine("LEFT JOIN Workflow w ON w.workflowid=swc.subworkflowid")
        sonsql.AppendLine("LEFT JOIN factory fa ON fa.factoryid=w.factoryid")
        sonsql.AppendLine("LEFT JOIN Workflowbase wb ON wb.workflowbaseid=w.workflowbaseid")
        sonsql.AppendLine("LEFT JOIN product p ON p.productid=c.productid")
        sonsql.AppendLine("LEFT JOIN productbase pb ON pb.productbaseid=p.productbaseid")
        sonsql.AppendLine("LEFT JOIN employee e ON e.employeeid=swc.checktechniqueid")
        sonsql.AppendLine("LEFT JOIN cdodefinition cdo ON cdo.cdodefid=w2.cdotypeid")
        sonsql.AppendLine("WHERE c.status=1 and cdo.cdoname='Workflow' AND swc.checkresult =0 AND c.containertype=7")
        If Not String.IsNullOrWhiteSpace(containerflag) Then
            sonsql.AppendFormat(" AND ({0}) AND W.factoryid='{1}' and c.containerid IN ({2})", containerflag, para("FactoryID"), para("ContainerIDs"))
        End If
        sonsql.AppendLine(" GROUP BY c.containerid,c.containername,swc.subworkflowcheckinfoid,P.PRODUCTID,C.TOGETHERFLAG,w.factoryid,C.CONTAINERTYPE,WS.WORKFLOWSTEPID,M.MFGORDERNAME,SWC.SUBWORKFLOWID")
        sonsql.AppendLine(" ORDER BY C.TOGETHERFLAG asc,c.containername ASC")
        Dim sonContainerDt As New DataTable
        If containerflag.Length > 0 Then '存在单件单卡的时候才查询子表
            sonContainerDt = DatabaseHelper.Query_ReturnDatTable(sonsql.ToString())
        Else
            sonContainerDt = tempDt.Clone
        End If
        Dim ds As New DataSet
        ds.Tables.Add(tempDt)
        ds.Tables(0).TableName = "sumContainer"
        ds.Tables.Add(sonContainerDt)
        ds.Tables(1).TableName = "sonContainer"
        If containerflag.Length > 0 Then '存在单件单卡的时候才关联
            ds.Relations.Add("sumContainer",
            New DataColumn() {ds.Tables(0).Columns("PRODUCTID"), ds.Tables(0).Columns("workflowid"), ds.Tables(0).Columns("TOGETHERFLAG"), ds.Tables(0).Columns("FactoryID"),
                              ds.Tables(0).Columns("CONTAINERTYPE"), ds.Tables(0).Columns("WORKFLOWSTEPID"), ds.Tables(0).Columns("MFGORDERNAME")},
            New DataColumn() {ds.Tables(1).Columns("PRODUCTID"), ds.Tables(1).Columns("workflowid"), ds.Tables(1).Columns("TOGETHERFLAG"), ds.Tables(1).Columns("FactoryID"),
                              ds.Tables(1).Columns("CONTAINERTYPE"), ds.Tables(1).Columns("WORKFLOWSTEPID"), ds.Tables(1).Columns("MFGORDERNAME")})
        End If

        Return ds
    End Function

    ''' <summary>
    ''' 更新子工艺校对表
    ''' create:Wangjh 20171214
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateSubWorkFlowCheckInfo(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.UpdateSubWorkFlowCheckInfo
        Dim updateSql As String = <string>
                                    UPDATE SubWorkflowCheckInfo swc SET swc.createemployeeid=:createemployeeid
                                  </string>

        If para.ContainsKey("ChecktechniqueID") Then
            updateSql += " ,swc.checktechniqueid='" + para("ChecktechniqueID") + "'"
        End If
        If para.ContainsKey("PlanEmployeeID") Then
            updateSql += ",SWC.PLANEMPLOYEEID='" + para("PlanEmployeeID") + "'"
        End If
        updateSql += "  WHERE swc.subworkflowcheckinfoid=:subworkflowcheckinfoid"
        Dim updatePara(1) As OracleParameter
        updatePara(0) = DatabaseHelper.NewParameter(":subworkflowcheckinfoid", para("SubWorkFlowCheckinfoID"), OracleType.VarChar)
        updatePara(1) = DatabaseHelper.NewParameter(":createemployeeid", para("CreateEmployeeID"), OracleType.VarChar)
        Dim i As Integer = DatabaseHelper.ExecuteSql(updateSql, updatePara)
        If i > 0 Then
            UpdateSubWorkFlowCheckInfo = True
        Else
            UpdateSubWorkFlowCheckInfo = False
        End If
    End Function
    ''' <summary>
    ''' 查询批次子工艺校对信息
    ''' add:Wangjh 20180314
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetSubWorkFlowInfo(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSContainerIBusiness.GetSubWorkFlowInfo
        Dim strSql As String = String.Format("SELECT * FROM subworkflowcheckinfo swc WHERE swc.containerid='{0}'", para("ContainerID"))
        If para.ContainsKey("SubWorkFlowID") Then
            strSql += String.Format(" AND swc.subworkflowid='{0}'", para("SubWorkFlowID"))
        End If
        If para.ContainsKey("WorkFlowID") Then
            strSql += String.Format(" AND swc.WorkFlowID='{0}'", para("WorkFlowID"))
        End If
        GetSubWorkFlowInfo = DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 更新总表工艺确认信息
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateContainerWfConfir(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.UpdateContainerWfConfir
        Dim strSql As String = "UPDATE containercurrentinfo cci SET cci.techniqueemployeeid=:techniqueemployeeid,cci.techniquedate=sysdate WHERE cci.containerid=:containerid"

        Dim updatePara(1) As OracleParameter
        updatePara(0) = DatabaseHelper.NewParameter(":techniqueemployeeid", para("EmployeeID"), OracleType.VarChar)
        updatePara(1) = DatabaseHelper.NewParameter(":containerid", para("ContainerID"), OracleType.VarChar)

        Dim i As Integer = DatabaseHelper.ExecuteSql(strSql, updatePara)
        LogHelp.WriteOrcale("工艺员记录检测" + "@^" + "已记录批次工艺员" + "@^" + "工艺员：" + para("EmployeeID") + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + para("ContainerID")) 'add:Wangjh 写入数据库   
        If i > 0 Then
            UpdateContainerWfConfir = True
        Else
            UpdateContainerWfConfir = False
        End If

    End Function

    ''' <summary>
    ''' 获取工艺最近选择的工艺员信息
    ''' </summary>
    ''' <param name="workflowID"></param>
    ''' <param name="type">0 主工艺 1 子工艺</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetWorkflowLatestCheckCheckTechniqueInfo(ByVal workflowID As String, ByVal type As String) As DataTable Implements uLMSContainerIBusiness.GetWorkflowLatestCheckCheckTechniqueInfo
        Dim strsql As New StringBuilder
        If type = "0" Then
            strsql.AppendLine("SELECT * FROM (")
            strsql.AppendLine("SELECT ua.attributevalue employeename,em.fullname FROM Userattribute ua")
            strsql.AppendLine("LEFT JOIN employee em on em.employeename = ua.attributevalue")
            strsql.AppendLine("LEFT JOIN container c ON c.containerid = ua.parentid")
            strsql.AppendFormat("WHERE  ua.userattributename ='CheckTechnique'  AND c.mfgworkflowid ='{0}'", workflowID)
            strsql.AppendLine("ORDER BY c.originalstartdate DESC")
            strsql.AppendLine(") a WHERE  Rownum=1")
        Else
            strsql.AppendLine("SELECT * FROM (")
            strsql.AppendLine("SELECT em.employeeid,em.employeename,em.fullname")
            strsql.AppendLine("FROM subworkflowcheckinfo swc")
            strsql.AppendLine("LEFT JOIN employee em ON em.employeeid = swc.checktechniqueid")
            strsql.AppendFormat("WHERE swc.subworkflowid='{0}' ", workflowID)
            strsql.AppendLine(" ORDER BY swc.createdate DESC")
            strsql.AppendLine(" ) a WHERE  Rownum=1")
        End If
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function

    ''' <summary>
    ''' 获取件号上一次开卡批次的类型和领料类型 create by tianFW 2018年6月8日
    ''' </summary>
    ''' <param name="productname"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetProductLastTimeContainerTypeAndIsSelfmfg(ByVal productname As String) As DataTable Implements uLMSContainerIBusiness.GetProductLastTimeContainerTypeAndIsSelfmfg
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT * FROM (")
        strsql.AppendLine("SELECT c.containertype,c.isselfmfg FROM productbase pb ")
        strsql.AppendLine("LEFT JOIN product p ON pb.productbaseid = p.productbaseid")
        strsql.AppendLine("LEFT JOIN container c ON c.productid = p.productid")
        strsql.AppendFormat("WHERE c.status <> -1 AND pb.productname='{0}' AND c.parentcontainerid IS NULL ORDER BY c.originalstartdate DESC) WHERE ROWNUM=1", productname)
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function


    ''' <summary>
    ''' 根据主工艺查询子工艺
    ''' add:Wangjh 20180725
    ''' </summary>
    ''' <param name="workflowID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetSubWorkflowByWorkflowid(ByVal workflowID As String) As DataTable Implements uLMSContainerIBusiness.GetSubWorkflowByWorkflowid
        Dim strSql As String = <string>
                            SELECT subw.workflowid subworkflowid,ws.workflowstepid,SUBE2.WORKFLOWNAME SUBWORKFLOWNAME  FROM workflow w 
                            LEFT JOIN Workflowstep ws ON ws.workflowid=w.workflowid
                            LEFT JOIN Workflowbase sube ON sube.workflowbaseid=ws.subworkflowbaseid
                            LEFT JOIN Workflow subw ON subw.workflowid=NVL(sube.revofrcdid,ws.subworkflowid)
                            LEFT JOIN WORKFLOWBASE SUBE2 ON SUBE2.WORKFLOWBASEID=SUBW.WORKFLOWBASEID
                               </string>
        strSql += "WHERE w.workflowid='" + workflowID + "' AND SUBW.WORKFLOWID IS NOT NULL"
        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function
    ''' <summary>
    ''' 更新子工艺校对表的时间
    ''' add:Wangjh 20180725
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateSubCheckWorkflowDate(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.UpdateSubCheckWorkflowDate
        Dim strSql As String = <string>UPDATE subworkflowcheckinfo swc SET swc.createdate =SYSDATE</string>
        strSql += String.Format(" WHERE swc.containerid='{0}' AND swc.workflowid='{1}'", para("ContainerID"), para("WorkFlowID"))
        Dim i As Integer = DatabaseHelper.ExecuteSql(strSql)
        If i > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 获取分批信息
    ''' add:Wangjh 20180821
    ''' </summary>
    ''' <param name="splitContainer"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetSplitInfoBySplitContainer(ByVal splitContainer As String) As DataTable Implements uLMSContainerIBusiness.GetSplitInfoBySplitContainer
        Dim strSql As String = <string>
                SELECT WS.WORKFLOWID,ws.sequence,CSI.*  FROM CONTAINERSPLITINFO CSI 
                LEFT JOIN WORKFLOWSTEP WS ON WS.WORKFLOWSTEPID=CSI.WORKFLOWSTEPID
                        </string>
        strSql += String.Format(" WHERE CSI.SPLITCONTAINERNAME='{0}' and csi.Isuse=0 ", splitContainer)
        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 判断批次是否被暂停
    ''' add:Wangjh 20180821
    ''' </summary>
    ''' <param name="IDs"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function IsHoldContainer(ByVal IDs As String) As Boolean Implements uLMSContainerIBusiness.IsHoldContainer
        Dim strSql As String = "SELECT * FROM containercurrentinfo cci WHERE cci.ishold=1 "
        strSql += String.Format(" AND cci.containerid IN ({0})", IDs)
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql)
        If dt.Rows.Count = 0 Then
            Return False
        Else
            Return True
        End If
    End Function

    ''' <summary>
    ''' 获取撤销的单件单卡信息  create by tianFW 2018-8-14
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetRepealSingletonContainerInfo(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSContainerIBusiness.GetRepealSingletonContainerInfo
        Dim strsql As New StringBuilder
        strsql.AppendLine("select c.containerid,c.containername,c.ishold from CONTAINERCURRENTINFO c")
        strsql.AppendFormat(" WHERE c.togetherflag='{0}' AND c.fromworkcenterid='{1}' AND c.workflowid='{2}'", para("TogetherFlag"), para("FromWorkCenterID"), para("WorkflowID"))
        strsql.AppendFormat(" AND c.workflowstepid='{0}' AND c.containerstatus= {1} ORDER BY C.CONTAINERNAME", para("WorkflowStepID"), para("ContainerStatus"))
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function

#Region "装试判断初检装或其他"
    ''' <summary>
    ''' 判断是否是初检装还是其他(试车集件等及其他分厂的东西)
    ''' Add by Yuxj20180620,和Yangsj讨论，固定查询 部装，传装，总装
    ''' </summary>
    ''' <param name="ContainerId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function CheckFirstSecondIssue(ByVal ContainerId As String) As String Implements uLMSContainerIBusiness.CheckFirstSecondIssue
        CheckFirstSecondIssue = String.Empty
        Dim sb As New StringBuilder
        With sb
            .AppendLine(" SELECT ep.containerno,ep.workflowid,ep.workflowstepid ")
            .AppendLine(" FROM enginepartplan ep ")
            .AppendLine(" LEFT JOIN workflow wf ON ep.workflowid=wf.workflowid ")
            .AppendLine(" where wf.assemblytype='装配' and wf.phasenode in ('部装','传装','总装') ")
            .AppendFormat(" and ep.containerId='{0}' ", ContainerId)
        End With
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(sb.ToString)
        If dt.Rows.Count > 0 Then
            '为部装，传装，总装之一，判断为初装or检装
            Dim ContainerNo As String = dt.Rows(0)("containerno").ToString
            Dim WorkflowId As String = dt.Rows(0)("workflowid").ToString
            Dim workflowstepid As String = dt.Rows(0)("workflowstepid").ToString 'Modify by Yuxj20181203

            '查询此任务单，处于此工艺下是否有超过一笔记录，如果超过，判断初检装
            sb = New StringBuilder
            With sb
                .AppendLine(" SELECT ep.containerid,ep.containername,wfs.workflowstepid,wfs.workflowstepname,wfs.sequence ")
                .AppendLine(" FROM enginepartplan ep ")
                .AppendLine(" LEFT JOIN workflow wf ON ep.workflowid=wf.workflowid ")
                .AppendLine(" LEFT JOIN workflowstep wfs ON ep.workflowstepid=wfs.workflowstepid ")
                .AppendLine(" where wf.assemblytype='装配' and wf.phasenode in ('部装','传装','总装') ")
                .AppendFormat(" and ep.containerNo='{0}' ", ContainerNo)
                .AppendFormat(" and ep.workflowid='{0}'", WorkflowId)
                .AppendLine(" ORDER BY wfs.sequence ASC ")
            End With

            dt = DatabaseHelper.Query_ReturnDatTable(sb.ToString)
            If dt.Rows.Count > 1 Then
                '有多笔记录才判断初检装
                If ContainerId = dt.Rows(dt.Rows.Count - 1)("containerid").ToString Then
                    'Modify by Yuxj20181203
                    If workflowstepid = dt.Rows(0)("workflowstepid").ToString Then
                        CheckFirstSecondIssue = "1"
                    Else
                        CheckFirstSecondIssue = "2"
                    End If

                Else
                    CheckFirstSecondIssue = "1"
                End If
            End If
        End If
    End Function
    ''' <summary>
    ''' add by longb 2024-03-12
    ''' 装配分厂判断包含（Z1:初装，Z2：检装）
    ''' </summary>
    ''' <param name="ContainerId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function CheckFirstSecondIssueNew(ByVal ContainerId As String) As String Implements uLMSContainerIBusiness.CheckFirstSecondIssueNew
        CheckFirstSecondIssueNew = String.Empty
        Dim sb As New StringBuilder
        sb.AppendLine(<string>SELECT m.MFGORDERNAME,p2.PRODUCTNAME  
                    FROM enginepartplan ep LEFT JOIN MFGORDER m ON m.MFGORDERID =ep.MFGORDERID
                    LEFT JOIN PRODUCT p ON p.PRODUCTID =m.PRODUCTID OR p.PRODUCTBASEID =m.PRODUCTBASEID 
                    LEFT JOIN PRODUCTBASE p2 ON p2.PRODUCTBASEID =m.PRODUCTBASEID 
                    where ep.containerId='{0}'</string>)
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(sb.ToString, ContainerId))
        If dt.Rows.Count > 0 Then
            CheckFirstSecondIssueNew = IIf(dt.Rows(0)("PRODUCTNAME").Contains("Z2"), "2", "1")
        End If
    End Function

#End Region

    ''' <summary>
    ''' 获取管理暂停批次信息 create by tianFW 2018年8月21日
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetOperStopContainerInfo(ByVal para As Dictionary(Of String, String)) As DTO.uMESProcessResult Implements uLMSContainerIBusiness.GetOperStopContainerInfo
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT k.mfgorderid,k.mfgordername,k.productid,k.productname,k.workflowroute,k.productdesc,k.fromworkcentername,")
        strsql.AppendLine("k.productbatch,k.togetherflag,k.containertypename,k.containertype,SUM(k.qty) totalqty,k.workflowname,k.workflowrevision,k.productrevision,")
        strsql.AppendLine("decode(k.ishold,'0','否','1','是') AS ishold,k.workflowstepid,k.workflowstepname")
        strsql.AppendLine("FROM (SELECT cu.mfgorderid,cu.mfgordername,cu.productid,cu.productname,cu.workflowroute,cu.workflowstepid,cu.workflowname,cu.workflowrevision,cu.productrevision,")
        strsql.AppendLine("cu.workflowstepname,cu.productdescription productdesc,(cu.productname || '/' || cu.containerno) productbatch,")
        strsql.AppendLine("decode(cu.containertype, 7, cu.togetherflag, cu.containername) togetherflag,")
        strsql.AppendLine("decode(cu.containertype,2,'批量加工',3,'批量带子序号',7,'单件加工') AS containertypename,")
        strsql.AppendLine("cu.containertype,cu.qty,nvl(cu.ishold,'0') ishold,cu.fromworkcentername")
        strsql.AppendLine("FROM containercurrentinfo cu")
        strsql.AppendLine(" LEFT JOIN OperContainerRecord ocr ON ocr.containerid = cu.containerid")
        strsql.AppendFormat(" WHERE cu.containerstatus=1 and cu.isinstore = '0' AND (cu.factoryid='{0}' OR cu.originalfactoryid='{0}')", para("factoryID"))
        If para.Keys.Contains("mfgOrderName") Then
            strsql.AppendFormat(" AND UPPER(cu.mfgordername) LIKE UPPER('%{0}%')", para("mfgOrderName"))
        End If
        If para.Keys.Contains("productName") Then
            strsql.AppendFormat(" AND UPPER(cu.productname) LIKE UPPER('%{0}%')", para("productName"))
        End If
        If para.Keys.Contains("containerName") Then
            strsql.AppendFormat(" AND UPPER(cu.containername) LIKE UPPER('%{0}%')", para("containerName"))
        End If
        If para.Keys.Contains("techEmployeeId") Then
            strsql.AppendFormat(" AND UPPER(cu.techniqueemployeeid) = UPPER('{0}')", para("techEmployeeId"))
        End If
        If para.Keys.Contains("reason") Then 'add by zhangrj 添加原因筛选 2022-4-21
            strsql.AppendFormat(" AND ocr.operreason in ({0})", para("reason"))
        End If
        strsql.AppendFormat(" AND NVL(cu.ishold,'0') = '{0}'", para("status"))
        strsql.AppendLine(") k GROUP BY k.mfgorderid,k.mfgordername,k.productid,k.productname,k.workflowroute,k.productdesc,k.productbatch,")
        strsql.AppendLine("k.togetherflag,k.containertypename,k.containertype,k.workflowname,k.workflowrevision,k.productrevision,k.ishold,k.workflowstepid,k.workflowstepname,k.fromworkcentername")
        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(para("CurrentPageIndex"))
        paraPage.PageSize = Convert.ToInt32(para("PageSize").ToString)
        paraPage.strSQL = strsql.ToString()
        Return DatabaseHelper.RunProcedureForPage(paraPage)
    End Function

    ''' <summary>
    ''' 获取管理暂停批次详细信息 create by tianFW 2018年8月21日
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetOperStopContainerDetailInfo(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSContainerIBusiness.GetOperStopContainerDetailInfo
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT cu.containerid,cu.containername,cu.qty,max(to_char(op.createdate,'yyyy-MM-dd')) createdate FROM containercurrentinfo cu")
        strsql.AppendLine(" LEFT JOIN opercontainerrecord op ON op.containerid = cu.containerid AND op.opertype = 2")
        If para.Keys.Contains("reason") Then 'add by zhangrj 添加原因筛选 2022-4-25
            strsql.AppendFormat(" AND op.operreason in ({0})", para("reason"))
        End If
        strsql.AppendFormat(" WHERE cu.containerstatus = 1 and cu.isinstore = 0 AND nvl(cu.ishold,'0') = '{0}' AND {1}", para("isHold"), para("valueStr"))
        strsql.AppendLine(" GROUP BY cu.containerid,cu.containername,cu.qty")
        strsql.AppendLine("ORDER BY cu.containername")
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function

    ''' <summary>
    ''' 更新批次暂停状态 add by tianFW 2018年8月22日
    ''' </summary>
    ''' <param name="containerids"></param>
    ''' <param name="type"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function OperContainerStop(ByVal containerids As String, ByVal type As Integer) As Boolean Implements uLMSContainerIBusiness.OperContainerStop
        Dim strsql As String = String.Format("UPDATE containercurrentinfo cu SET cu.ishold = '{0}' WHERE cu.containerid IN ({1})", type, containerids)
        If DatabaseHelper.ExecuteSql(strsql) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 获取批次暂停原因
    ''' </summary>
    ''' <param name="containerid"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetContainerStopReason(ByVal containerid As String) As DataTable Implements uLMSContainerIBusiness.GetContainerStopReason
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT * FROM (")
        strsql.AppendLine("SELECT k.*,ROWNUM rn FROM (")
        strsql.AppendLine("SELECT ocr.operreason reasonname,ocr.containerid,ocr.createdate")
        strsql.AppendLine(" FROM operContainerRecord ocr")
        strsql.AppendFormat(" WHERE ocr.containerid='{0}'", containerid)
        strsql.AppendLine("ORDER BY ocr.createdate DESC")
        strsql.AppendLine(" ) k ) V WHERE v.rn = 1")
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function

    ''' <summary>
    ''' 批次暂停
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerHold(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal strReason As String, ByRef strMsg As String) As Boolean Implements uLMSContainerIBusiness.ContainerHold
        ContainerHold = False
        Dim strInfo As String = ""
        Dim strTxnDocName, strTxnName As String
        strTxnDocName = "HoldDoc"
        strTxnName = "Hold"
        Dim m_DataList As New List(Of ClientAPIEntity)
        m_DataList.Add(New ClientAPIEntity("Container", InputTypeEnum.Details, DataTypeEnum.ContainerField, strContainerName, ""))
        m_DataList.Add(New ClientAPIEntity("HoldReason", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, strReason, ""))
        Dim clientData As New CamstarClientAPI(host.UserName, host.Password)
        ContainerHold = clientData.RunTxnService(strTxnDocName, strTxnName, m_DataList, strMsg)
    End Function

    ''' <summary>
    ''' 批次释放
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerRelease(ByVal host As ServerHostInfo, ByVal strContainerName As String, ByVal strReason As String, ByRef strMsg As String) As Boolean Implements uLMSContainerIBusiness.ContainerRelease
        ContainerRelease = False
        Dim strInfo As String = ""
        Dim strTxnDocName, strTxnName As String
        strTxnDocName = "ReleaseDoc"
        strTxnName = "Release"
        Dim m_DataList As New List(Of ClientAPIEntity)
        m_DataList.Add(New ClientAPIEntity("Container", InputTypeEnum.Details, DataTypeEnum.ContainerField, strContainerName, ""))
        m_DataList.Add(New ClientAPIEntity("ReleaseReason", InputTypeEnum.Details, DataTypeEnum.NamedObjectField, strReason, ""))
        Dim clientData As New CamstarClientAPI(host.UserName, host.Password)
        ContainerRelease = clientData.RunTxnService(strTxnDocName, strTxnName, m_DataList, strMsg)
    End Function

    ''' <summary>
    ''' 获取批次操作信息 create by tianFW 2018年8月28日
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetOperContaienrInfo(ByVal para As Dictionary(Of String, String)) As uMESProcessResult Implements uLMSContainerIBusiness.GetOperContaienrInfo
        Dim strsql As String =
            <string>
                SELECT ocr.containerid,ocr.containername,ocr.createdate,em.employeeid,em.fullname opername,ocr.operreason reason,
			           decode(ocr.opertype, 1, '删除' ，2， '暂停', 3, '释放') opertype,ocr.operatorid,ocr.productname,ocr.qty
                FROM opercontainerrecord ocr
                LEFT JOIN employee em ON em.employeeid = ocr.operatorid
                LEFT JOIN container c ON c.containerid = ocr.containerid
            </string>
        If para("type") = "1" Then
            strsql += " WHERE ocr.opertype = 1 "
        Else
            If para("type") = "4" Then '4是暂停或释放的全部信息
                strsql += " WHERE ocr.opertype <> 1 "
            ElseIf para("type") = "2" Then
                strsql += " WHERE ocr.opertype = 2 "
            ElseIf para("type") = "3" Then
                strsql += " WHERE ocr.opertype = 3 "
            End If
        End If
        If para.Keys.Contains("scanContainer") Then
            strsql += String.Format(" AND ocr.containername = '{0}' ", para("scanContainer"))
        ElseIf para.Keys.Contains("containerName") Then
            strsql += String.Format(" AND UPPER(ocr.containername) like UPPER('%{0}%') ", para("containerName"))
        End If
        If para.Keys.Contains("productName") Then
            strsql += String.Format(" AND UPPER(ocr.productname) like UPPER('%{0}%') ", para("productName"))
        End If
        strsql += String.Format(" AND c.originalfactoryid='{0}'", para("factoryID"))
        strsql += "  ORDER BY ocr.containername,ocr.createdate"
        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(para("CurrentPageIndex"))
        paraPage.PageSize = Convert.ToInt32(para("PageSize").ToString)
        paraPage.strSQL = strsql.ToString()
        Return DatabaseHelper.RunProcedureForPage(paraPage)
    End Function

    ''' <summary>
    ''' 修改批次数量 create by tianFW 2018年8月30日
    ''' </summary>
    ''' <param name="containerid">批次ID</param>
    ''' <param name="qty">修改数量</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function ChangeContainerQty(ByVal containerid As String, ByVal qty As Integer) As Boolean Implements uLMSContainerIBusiness.ChangeContainerQty
        ChangeContainerQty = False
        '更新总表一些信息
        Dim updatePara As New Dictionary(Of String, String)
        Dim conditionPara As New Dictionary(Of String, String)
        conditionPara("ContainerID") = "'" + containerid + "'"
        '

        Dim strsql As String = String.Format("UPDATE container c SET c.qty = c.qty +({0}) WHERE c.containerid = '{1}'", qty, containerid)
        If DatabaseHelper.ExecuteSql(strsql) > 0 Then
            strsql = String.Format("SELECT C.QTY,C.STATUS FROM CONTAINER C WHERE C.CONTAINERID='{0}'", containerid)
            Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(strsql)
            strsql = ""
            Dim dr As DataRow = dt.Rows(0)

            If Convert.ToInt64(dr("QTY")) <= 0 And Convert.ToInt64(dr("STATUS")) <> 2 Then
                strsql = String.Format("UPDATE CONTAINER C SET C.STATUS = 2 WHERE C.CONTAINERID='{0}'", containerid)
                updatePara("ContainerSTATUS") = 2
            ElseIf Convert.ToInt64(dr("QTY")) > 0 And Convert.ToInt64(dr("STATUS")) <> 1 Then
                strsql = String.Format("UPDATE CONTAINER C SET C.STATUS = 1 WHERE C.CONTAINERID='{0}'", containerid)
                updatePara("ContainerSTATUS") = 1
            End If
            '更新总表一些信息
            updatePara("Qty") = dr("QTY")
            m_ConCurrentinfoObj.UpdateContainerCurrentInfoByField(updatePara, conditionPara)
            '
            If strsql <> "" Then
                If DatabaseHelper.ExecuteSql(strsql) > 0 Then 
                    Return True
                End If
            Else
                Return True
            End If
        End If
    End Function

    ''' <summary>
    ''' 增加检验批次数量改变记录 create by tianFW 2018年8月30日
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function AddCheckQtyChangeRecord(ByVal para As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.AddCheckQtyChangeRecord
        AddCheckQtyChangeRecord = False
        Dim objPara As Object()
        objPara = FillCheckQtyChangeRecord(para)
        If DatabaseHelper.ExecuteSql(objPara.First, objPara.Last) > 0 Then
            Return True
        End If
    End Function
    Function FillCheckQtyChangeRecord(ByVal para As Dictionary(Of String, String)) As Object() Implements uLMSContainerIBusiness.FillCheckQtyChangeRecord
        Dim strsql As String = <string>
                INSERT INTO CheckQtyChangeRecord(Checkqtychangerecordid,Containercheckinfoid,Containerid,Changeqtytype,Isuse,Qty,Reasonid,Scrapsourcetype,
                Containerstepworkreportid,Createdate,Employeeid,Workflowstepid,Stepinfoid)
                VALUES(:Checkqtychangerecordid,:Containercheckinfoid,:Containerid,:Changeqtytype,0,:Qty,:Reasonid,:Scrapsourcetype,
				:Containerstepworkreportid,Sysdate,:Employeeid,:Workflowstepid,:Stepinfoid)
            </string>
        Dim insertPara(10) As OracleParameter
        insertPara(0) = DatabaseHelper.NewParameter(":Checkqtychangerecordid", System.Guid.NewGuid.ToString(), OracleType.VarChar)
        insertPara(1) = DatabaseHelper.NewParameter(":Containercheckinfoid", para("containerCheckInfoID"), OracleType.VarChar)
        insertPara(2) = DatabaseHelper.NewParameter(":Containerid", para("containerID"), OracleType.VarChar)
        insertPara(3) = DatabaseHelper.NewParameter(":Changeqtytype", para("changeQtyType"), OracleType.Number)
        insertPara(4) = DatabaseHelper.NewParameter(":Qty", para("qty"), OracleType.Number)
        insertPara(5) = DatabaseHelper.NewParameter(":Reasonid", para("reasonID"), OracleType.VarChar)
        insertPara(6) = DatabaseHelper.NewParameter(":Scrapsourcetype", Integer.Parse(para("scrapSourceType")), OracleType.Number)
        If String.IsNullOrWhiteSpace(para("containerStepWorkReportID")) Then
            insertPara(7) = DatabaseHelper.NewParameter(":Containerstepworkreportid", DBNull.Value, OracleType.VarChar)
        Else
            insertPara(7) = DatabaseHelper.NewParameter(":Containerstepworkreportid", para("containerStepWorkReportID"), OracleType.VarChar)
        End If
        insertPara(8) = DatabaseHelper.NewParameter(":Employeeid", para("EmployeeID"), OracleType.VarChar)
        insertPara(9) = DatabaseHelper.NewParameter(":Workflowstepid", para("WorkflowstepID"), OracleType.VarChar)

        If para.ContainsKey("StepInfoID") Then '新增工步的记录 add by zhangrj 2022-09-27
            insertPara(10) = DatabaseHelper.NewParameter(":Stepinfoid", para("StepInfoID"), OracleType.VarChar)
        Else
            insertPara(10) = DatabaseHelper.NewParameter(":Stepinfoid", DBNull.Value, OracleType.VarChar)
        End If

        Return New Object() {strsql, insertPara}
    End Function

    ''' <summary>
    ''' 获取成品检验批次报废报工记录对应的报废数 create by tianFW 2018年9月12日
    ''' </summary>
    ''' <param name="containercheckID"></param>
    ''' <returns></returns>
    ''' <remarks>只查询报废的，不查询超报的</remarks>
    Function GetCheckQtyChangeRecordOfWorkReportLossInfo(ByVal containercheckID As String) As DataTable Implements uLMSContainerIBusiness.GetCheckQtyChangeRecordOfWorkReportLossInfo
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT SUM(ccr.qty) lossqty,ccr.containerstepworkreportid")
        strsql.AppendLine("FROM checkqtychangerecord ccr")
        strsql.AppendLine("LEFT JOIN containerstepworkreport csw")
        strsql.AppendLine("ON csw.containerstepworkreportid = ccr.containerstepworkreportid")
        strsql.AppendFormat("WHERE ccr.containercheckinfoid = '{0}' AND csw.isuse = 0 and ccr.changeqtytype = 2", containercheckID)
        strsql.AppendLine("GROUP BY ccr.containerstepworkreportid")
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function


    ''' <summary>
    ''' 获取批量带子序号的报废记录 create by tianFW 2018年9月10日
    ''' </summary>
    ''' <param name="IDs">报工IDs或检验ID</param>
    ''' <param name="type">1 根据报工ID查询 2 根据检验ID查询</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetContainerHaveChildsOfLossChilds(ByVal IDs As String, ByVal type As Integer) As DataTable Implements uLMSContainerIBusiness.GetContainerHaveChildsOfLossChilds
        Dim strsql As String = ""
        If type = 1 Then
            strsql = String.Format("  SELECT c.containername,c.containerid FROM containerstepworkreportchild cswc" +
                                   "  LEFT JOIN container c ON c.containerid = cswc.childcontainerid " +
                                   "  WHERE c.status = 2 AND cswc.containerstepworkreportid IN ({0})", IDs)
        Else
            strsql = String.Format("   SELECT c.containername,c.containerid FROM CheckQtyChangeRecord ccr " +
                                    "  LEFT JOIN container c ON c.containerid = ccr.containerid " +
                                    "  WHERE c.status = 2 AND ccr.containercheckinfoid IN ({0})", IDs)
        End If
        Return DatabaseHelper.Query_ReturnDatTable(strsql)
    End Function

    ''' <summary>
    ''' 获取没有子工艺开卡的信息 create by tianFW 2018年9月14日
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetSubWFProductOfNoContainer(ByVal para As Dictionary(Of String, String)) As uMESProcessResult Implements uLMSContainerIBusiness.GetSubWFProductOfNoContainer
        Dim strsql As New StringBuilder
        Dim strsqlvalue As String =
            <string>SELECT cu.mfgorderid,cu.mfgordername,cu.productid,cu.productname,cu.productname || '/' || cu.containerno productbatch,c.uomid,u.uomname,
cu.containertype,decode(cu.containertype,7,'单件单卡','2','数量批','3','批量带子序号') containertypename,cu.isselfmfg,sum(cu.qty) wipqty,
cu.productrevision productrev,decode(cu.workflowname,'MW',fwb.workflowname,'MW1',fwb.workflowname,cu.workflowname) workflowname,
decode(cu.workflowname,'MW',c.mfgworkflowid,'MW1',c.mfgworkflowid,cu.workflowid) workflowid,
decode(cu.workflowname,'MW',fwf.workflowrevision,'MW1',fwf.workflowrevision,cu.workflowrevision) workflowrev,
sp.productid subproductid,spb.productname subproductname,sp.description subproductdesc,sp.productrevision subproductrev,cuswf.subworkflowid,swf.process_no SubProcessNo,swf.workflowrevision subwrokflowrev,
swb.workflowname subworkflowname,swf.zgemployeeid techniqueid,em.employeename technique,em.fullname techniquefull,t.teamid,t.teamname,
cu.fromworkcenterid workcenterid,cu.fromworkcentername workcentername,c.originalfactoryid,cu.familylistnames,cu.togetherflag,cu.plannedstartdate,
cu.plannedcompletiondate,sonc.togetherflag stogetherflag 
FROM containercurrentinfo cu
LEFT JOIN container c ON c.containerid = cu.containerid
LEFT JOIN workflow fwf ON fwf.workflowid = c.mfgworkflowid
LEFT JOIN workflowbase fwb ON fwb.workflowbaseid = fwf.workflowbaseid
LEFT JOIN team t ON t.teamid = c.teamid
LEFT JOIN uom u ON u.uomid = c.uomid
--1.获取分段件号的件号信息以及艺路线信息
LEFT JOIN productbase pb ON pb.productname = cu.workflowroute
LEFT JOIN product p ON p.productbaseid = pb.productbaseid
LEFT JOIN productworkflowmapping wf ON wf.productid = p.productid
--2.获取批次当前工艺的子工艺及默认工艺员
inner JOIN (
--此情况还要过滤掉子工艺为第二层虚拟工艺情况
SELECT sbs.workflowid,sbs.sonworkflowid subworkflowid FROM stepsubstep sbs
left join workflowstep sws on sws.workflowstepid=sbs.sonworkflowstepid--子工艺的工序  
left join specbase sb on sb.specbaseid=sws.specbaseid
left join spec s on s.specid=nvl(sb.revofrcdid,sws.specid)----子工艺的工序
where NVL2(s.commonsubworkflow,'1','0')='0' and exists (select 1 from workflowstep ws where ws.workflowstepid=sbs.workflowstepid and ws.wipmsglabel='子工艺')          
GROUP BY sbs.workflowid,sbs.sonworkflowid
      
union all            
--子工艺只有一个序的情况，默认子工艺为虚拟工艺，查孙工艺（通用工艺）
SELECT sbs.workflowid,subw.workflowid subworkflowid FROM (
SELECT w.workflowid  FROM workflow w
LEFT JOIN workflowstep ws ON ws.workflowid=w.workflowid
WHERE w.factoryid='{0}'
GROUP BY w.workflowid
having count(ws.workflowstepid)=1
) w--通用工艺情况下，第二层虚拟子工艺 
LEFT JOIN workflowstep ws ON ws.workflowid=w.workflowid
left join specbase sb on sb.specbaseid=ws.specbaseid
left join spec s on s.specid=nvl(sb.revofrcdid,ws.specid)        
INNER join workflow subw on subw.process_no=s.commonsubworkflow--通用孙子工艺
inner join workflowbase swb on swb.revofrcdid=subw.workflowid
LEFT JOIN stepsubstep sbs ON sbs.sonworkflowid=w.workflowid--第二层虚拟子工艺的关联信息
INNER JOIN workflow fw ON fw.workflowid=sbs.workflowid--第一层工艺，主工艺
WHERE   NVL2(s.commonsubworkflow,'1','0')='1'  and exists (select 1 from workflowstep ws where ws.workflowstepid=sbs.workflowstepid and ws.wipmsglabel='子工艺')
GROUP BY sbs.workflowid,subw.workflowid

) cuswf
--2.1如果是分段件号，则使用与原件号默认工艺路线ID
ON cuswf.workflowid = decode(cu.workflowroute,null,decode(cu.isinstore,0,cu.workflowid, c.mfgworkflowid),wf.workflowid) 

LEFT JOIN workflow swf ON swf.workflowid = cuswf.subworkflowid
LEFT JOIN workflowbase swb ON swb.workflowbaseid = swf.workflowbaseid
LEFT JOIN employee em ON em.employeeid = swf.zgemployeeid
--3获取件号关联表中子件号关联工艺
LEFT JOIN product sp on sp.productid=swf.productid
left join productbase spb on spb.productbaseid=sp.productbaseid
--子卡信息
left join containersubcontainer cc on cc.containerid=cu.containerid and cc.subprocessno=swf.process_no
LEFT JOIN container sonc ON sonc.containerid=cc.subcontainerid AND sonc.status=1

LEFT JOIN product cup ON cup.productid = cu.productid
LEFT JOIN producttype pt ON pt.producttypeid = cup.producttypeid
WHERE cu.containerstatus = 1 AND CU.isinstore =0 </string>.Value
        strsqlvalue = String.Format(strsqlvalue, para("factoryID"))
        strsql.AppendLine(strsqlvalue)
        strsql.AppendFormat(" AND swf.factoryid = '{0}' ", para("factoryID"))
        strsql.AppendLine(" AND pt.producttypename<>'子工艺虚拟件' ") 
        If para("status") = "0" Then
            strsql.AppendLine(<string> AND NOT EXISTS(SELECT 1 FROM containersubcontainer cc1 
            LEFT JOIN container sonc1 ON sonc1.containerid=cc1.subcontainerid 
            WHERE cc1.containerid=cu.containerid and cc1.subprocessno=swf.process_no AND sonc1.status=1 AND NVL(cc1.isuse,0) = 0
            ) </string>.Value)
            'strsql.AppendLine(" and nvl2(sonc.containerid,'1','0')='0' ")
        Else
            strsql.AppendLine(" and nvl2(sonc.containerid,'1','0')='1' ")
        End If
        If para.Keys.Contains("mfgOrderName") Then
            strsql.AppendFormat(" AND cu.mfgordername LIKE '%{0}%' ", para("mfgOrderName"))
        End If
        If para.Keys.Contains("productName") Then
            strsql.AppendFormat(" and cu.productname like '%{0}%' ", para("productName"))
        End If
        If para.Keys.Contains("childWFName") Then
            strsql.AppendFormat(" AND swb.workflowname LIKE '%{0}%' ", para("childWFName"))
        End If
        strsqlvalue =
            <string> GROUP BY cu.mfgorderid,cu.mfgordername,cu.productid,cu.productname,cu.containerno,cu.containertype,cu.productrevision,c.uomid,fwb.workflowname,
c.mfgworkflowid,fwf.workflowrevision,cu.isselfmfg,sp.productid,spb.productname,sp.description ,sp.productrevision,swb.workflowname,
swf.workflowrevision,cuswf.subworkflowid,swf.zgemployeeid,em.employeename,em.fullname,t.teamid,t.teamname,c.originalfactoryid,cu.fromworkcenterid,
cu.fromworkcentername,u.uomname,cu.familylistnames,cu.togetherflag,cu.plannedstartdate,cu.plannedcompletiondate,sonc.togetherflag,sonc.containertype,
cu.workflowname,cu.workflowid,cu.workflowrevision,swf.process_no  </string>
        strsql.AppendLine(strsqlvalue)
        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(para("CurrentPageIndex").ToString)
        paraPage.PageSize = Convert.ToInt32(para("PageSize").ToString)
        paraPage.strSQL = strsql.ToString()
        Dim result = DatabaseHelper.RunProcedureForPage(paraPage)

        '查询每个子工艺的第一个父工序
        Dim sq = <string>SELECT * FROM 
(
SELECT sbs.workflowid,sbs.workflowstepid,fws.workflowstepname,sbs.sonworkflowid subworkflowid FROM stepsubstep sbs
left join workflowstep sws on sws.workflowid=sbs.sonworkflowid--子工艺的工序   
left join workflowstep fws on fws.workflowstepid=sbs.workflowstepid--父工序
where sbs.sonworkflowid='{0}' and sbs.workflowid='{1}'
GROUP BY sbs.workflowid,sbs.sonworkflowid,sbs.workflowstepid,sbs.sonworkflowname,fws.workflowstepname
having count(sws.workflowstepid)>1      
union all            
--子工艺只有一个序的情况，默认子工艺为虚拟工艺，查孙工艺（通用工艺）
SELECT sbs.workflowid,sbs.workflowstepid,fws.workflowstepname,subw.workflowid subworkflowid FROM stepsubstep sbs    
left join workflowstep fws on fws.workflowstepid=sbs.workflowstepid--父工序         
left join workflowstep sws on sws.workflowid=sbs.sonworkflowid--子工艺的工序  
left join specbase sb on sb.specbaseid=sws.specbaseid
left join spec s on s.specid=nvl(sb.revofrcdid,sws.specid)            
left join workflow subw on subw.process_no=s.commonsubworkflow--通用孙子工艺
inner join workflowbase swb on swb.revofrcdid=subw.workflowid 
 where subw.workflowid='{0}' and sbs.workflowid='{1}'        
GROUP BY sbs.workflowid,sbs.workflowstepid,subw.workflowid,fws.workflowstepname
having count(sws.workflowstepid)=1
) t ORDER BY t.subworkflowid,t.workflowstepid </string>.Value
        If result.DBTable.Rows.Count > 0 Then
            result.DBTable.Columns.Add("workflowstepid") '父工序ID
            result.DBTable.Columns.Add("workflowstepname") '父工序name
            For Each r In result.DBTable.Rows
                Dim tempDt = DatabaseHelper.Query_ReturnDatTable(String.Format(sq, r("subworkflowid").ToString(), r("workflowid").ToString))
                If tempDt.Rows.Count > 0 Then
                    r("workflowstepid") = tempDt.Rows(0)("workflowstepid")
                    r("workflowstepname") = tempDt.Rows(0)("workflowstepname")
                End If
            Next
        End If
        result.DBTable.AcceptChanges()

        Return result
    End Function

    ''' <summary>
    ''' 获取父工艺开卡的批次
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetFaWFContainerInfo(ByVal para As Dictionary(Of String, String)) As DataTable Implements uLMSContainerIBusiness.GetFaWFContainerInfo
        Dim strsql As New StringBuilder
        Dim strsql_ As String = ""
        If para("type") = "Fwfcontainer" Then
            If para("containerType") <> "3" Then
                strsql.AppendLine("SELECT cu.containerid oldContainerID,cu.containername,cu.qty,cu.familylistnames,cu.familylistids,wc.workcentername,t.teamname")
                strsql.AppendLine(",wc.workcenterid,t.teamid")
                strsql.AppendLine("FROM CONTAINER C")
                strsql.AppendLine("LEFT JOIN containercurrentinfo cu ON C.CONTAINERID = CU.CONTAINERID")
                strsql.AppendFormat(<string>  left join containersubcontainer csc on csc.containerid=cu.containerid and csc.subprocessno='{0}'
 left join container cc on cc.containerid=csc.subcontainerid and cc.status!=0 </string>.Value, para("SubProcessNo"))
            Else
                strsql.AppendLine("SELECT c.containerid oldContainerID,c.containername fcontainername,cc.containername,cc.qty,cu.familylistnames,cu.familylistids")
                strsql.AppendLine(",wc.workcenterid,t.teamid,wc.workcentername,t.teamname")
                strsql.AppendLine("FROM CONTAINER C")
                strsql.AppendLine("LEFT JOIN containercurrentinfo cu ON C.CONTAINERID = CU.CONTAINERID")
                strsql.AppendLine("LEFT JOIN container cc ON cc.parentcontainerid = c.containerid and cc.status=1 ")
            End If
            strsql.AppendLine("LEFT JOIN WORKCENTER WC ON WC.WORKCENTERID = C.WORKCENTERID")
            strsql.AppendLine("LEFT JOIN Team t ON t.TeamID = C.TeamID")
            strsql.AppendFormat(" WHERE c.mfgorderid='{0}' AND cu.productid='{1}'", para("mfgOrderID"), para("productID"))
            strsql.AppendFormat(" AND decode(cu.workflowname,'MW',c.mfgworkflowid,'MW1',c.mfgworkflowid,cu.workflowid)  = '{0}' AND cu.containerno ='{1}'", para("workflowID"), para("containerNO"))
            strsql.AppendFormat(" AND cu.isselfmfg='{0}' AND cu.containerstatus = 1 and cu.familylistNames = '{1}'", para("isSelemfg"), para("familylistNames"))
            If para("containerType") = "3" Then
                strsql.AppendLine(" AND c.status = 1")
            Else
                strsql.AppendLine(" AND cc.containerid is null")
            End If
            strsql_ = "select Distinct * from (" + strsql.ToString() & ") order by containername"
        Else
            If para("containerType") <> "3" Then
                strsql.AppendLine("SELECT cu.mfgordername,c.containername,")
            Else
                strsql.AppendLine("SELECT cu.mfgordername,c.containername fcontainername,cc.containername,")
            End If
            strsql.AppendLine("cu.productname,cu.productrevision productRev,wb.workflowname,wf.workflowrevision wrokflowRev,c.qty,")
            strsql.AppendLine("em.fullname techniqueFull,u1.attributevalue beginStep,replace(c.mfgbatch,'型别：','') familyListNames_,")
            strsql.AppendLine("cu.fromworkcentername workcentername,t.teamname")
            strsql.AppendLine("FROM container c")
            strsql.AppendLine("LEFT JOIN containercurrentinfo cu ON cu.containerid = c.containerid")
            If para("containerType") = "3" Then
                strsql.AppendLine("LEFT JOIN container cc ON cc.parentcontainerid = c.containerid and cc.status=1 ")
            End If
            strsql.AppendLine("LEFT JOIN team t ON t.teamid = c.teamid")
            strsql.AppendLine("LEFT JOIN Userattribute u ON u.parentid = c.containerid AND u.userattributename='CheckTechnique'")
            strsql.AppendLine("LEFT JOIN employee em ON em.employeename = u.attributevalue ")
            strsql.AppendLine("LEFT JOIN Workflow wf ON wf.workflowid = c.mfgworkflowid")
            strsql.AppendLine("LEFT JOIN Workflowbase wb ON wb.workflowbaseid = wf.workflowbaseid")
            strsql.AppendLine("LEFT JOIN Userattribute u1 ON u1.parentid = c.containerid AND u1.userattributename='BeginStep'")
            strsql.AppendFormat(" WHERE c.mfgorderid='{0}' AND cu.productid='{1}'", para("mfgOrderID"), para("productID"))
            strsql.AppendFormat(" AND c.mfgworkflowid = '{0}' AND c.togetherflag ='{1}'", para("workflowID"), para("togetherflag"))
            strsql.AppendFormat(" AND cu.isselfmfg='{0}' AND cu.containerstatus = 1 and cu.familylistNames = '{1}'", para("isSelemfg"), para("familylistNames"))
            strsql.AppendFormat(" AND cu.containerno='{0}'", para("productBatch"))
            If para("containerType") = "3" Then
                strsql.AppendLine(" AND cc.status = 1")
            End If
            strsql_ = "select k.*,replace(k.familyListNames_,'|','') familyListNames from (" + strsql.ToString() & ") k order by containername"
        End If

        Return DatabaseHelper.Query_ReturnDatTable(strsql_)
    End Function

    ''' <summary>
    ''' 判断批次和工序是否工序或成品检验完
    ''' add:Wangjh 20220309
    ''' </summary>
    ''' <param name="contaienrid"></param>
    ''' <param name="stepid"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function JudgeContainerStepIsFinish(ByVal contaienrid As String, ByVal stepid As String) As uMESProcessResult Implements uLMSContainerIBusiness.JudgeContainerStepIsFinish
        Dim result = New uMESProcessResult
        result.Result = False

        'yuxj20221107 如果为外委工序，且已经转回，不参与排产
        If CheckCommisioning(contaienrid, stepid) Then
            result.Result = True
            Return result
        End If

        Dim strSql = <string>select cci.qty,sum(cc.acceptanceqty) sumpassqty,sum(cf.acceptanceqty) sumpassqty2 from containercurrentinfo cci
left join containercheckinfo cc on cc.containerid=cci.containerid and cc.workflowstepid='{0}' and cc.isuse=0
left join containerfinishedcheckinfo cf on cf.containerid=cci.containerid and cf.workflowstepid='{0}' and cf.isuse=0
where cci.containerid='{1}'                             
group by cci.qty</string>.Value
        Dim dt = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, stepid, contaienrid))

        If dt.Rows.Count > 0 Then
            Dim wipqty = 0
            Dim sumpassqty = 0
            Dim sumpassqty2 = 0
            If Not String.IsNullOrWhiteSpace(dt.Rows(0)("qty").ToString) Then
                wipqty = Val(dt.Rows(0)("qty").ToString)
            End If
            If Not String.IsNullOrWhiteSpace(dt.Rows(0)("sumpassqty").ToString) Then
                sumpassqty = Val(dt.Rows(0)("sumpassqty").ToString)
            End If
            If Not String.IsNullOrWhiteSpace(dt.Rows(0)("sumpassqty2").ToString) Then
                sumpassqty2 = Val(dt.Rows(0)("sumpassqty2").ToString)
            End If

            If sumpassqty >= wipqty Or sumpassqty2 >= wipqty Then
                result.Result = True
                Return result
            End If
            '如果是返修，试件报工，不用干完也算完成
            If DatabaseHelper.GetSingle(String.Format(<string>SELECT 1 FROM containerstepworkreport csw WHERE csw.containerid='{0}' AND csw.workflowstepid='{1}' AND csw.isuse=0 AND (
csw.checktype=4 OR csw.checktype=3 OR csw.specimenqty IS NOT NULL
)</string>.Value, contaienrid, stepid)) IsNot Nothing Then
                result.Result = True
                Return result
            End If
        End If

        '如果传入序没有加工记录，则检查他的子工艺信息
        strSql = "select ws.* from workflowstep ws where ws.workflowstepid='{0}'  "

        Dim wsDt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, stepid))
        If wsDt.Rows(0)("wipmsglabel").ToString = "子工艺" Then
            strSql = <string>select sc.isinstore  from containersubcontainer cc
    inner join containercurrentinfo sc on sc.containerid=cc.subcontainerid--子卡
    LEFT JOIN workflowstep ws ON ws.workflowstepid=cc.workflowstepid
    where cc.containerid='{0}' and ws.workflowstepname='{1}' </string>.Value
            Dim tempDt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, contaienrid, wsDt.Rows(0)("workflowstepname").ToString))
            If tempDt.Rows.Count = 0 Then
                result.Message = "转工序没开子卡，无法转工完成"
            Else
                If tempDt.Select("isinstore<>1").Length = 0 Then
                    result.Result = True
                    Return result
                Else
                    result.Message = "转工序的子卡没完成，无法转工完成"
                End If
            End If
        Else
            result.Message = "转工序无检验记录，无法转工完成"
        End If

        Return result
    End Function

    ''' <summary>
    ''' yuxj20221107 判断某道工序，是否为外委,且外委已转回
    ''' </summary>
    ''' <param name="contaienrid"></param>
    ''' <param name="stepid"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function CheckCommisioning(ByVal contaienrid As String, ByVal stepid As String) As Boolean
        CheckCommisioning = False
        Dim strsql As String =
            <string>
                select wfs.workflowid,wfs.sequence from workflowstep wfs where wfs.workflowstepid='{0}'
            </string>
        Dim dtStep As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(strsql, stepid))
        Dim workflowid As String = dtStep.Rows(0)("workflowid").ToString
        Dim seq As String = Convert.ToInt32(dtStep.Rows(0)("sequence"))

        strsql =
            <string>
                select cm.containercommissioningid,wfs.workflowid,wfs.sequence in_seq,wfs1.sequence out_seq  
                from containercommissioning cm 
                left join workflowstep wfs on wfs.workflowstepid=cm.workflowstepid
                left join workflowstep wfs1 on wfs1.workflowstepid=cm.inworkflowstepid
                where cm.containerid='{0}' and cm.indate is not null and wfs.workflowid='{1}' 
            </string>
        strsql = String.Format(strsql, contaienrid, workflowid)
        strsql += String.Format(" and wfs.sequence<={0} and wfs1.sequence>{0} ", seq)
        Dim dt = DatabaseHelper.Query_ReturnDatTable(strsql)
        If dt.Rows.Count > 0 Then
            CheckCommisioning = True
        End If

    End Function



    ''' <summary>
    ''' 批次新旧工艺规程排产数据继承
    ''' 条件：新工艺没有任何排产数据，旧工艺有排产数据
    ''' add:Wangjh 20220526
    ''' yuxj20221108增加 s.factoryid并在插入时赋值
    ''' </summary>
    ''' <param name="containerId"></param>
    ''' <param name="oldWorkflowId"></param>
    ''' <param name="newWorkflowId"></param>
    ''' <remarks></remarks>
    Public Sub InheritConSpecPlan(ByVal containerId As String, ByVal oldWorkflowId As String, ByVal newWorkflowId As String) Implements uLMSContainerIBusiness.InheritConSpecPlan
        Dim strSpecPlan = <string>select  s.factoryid,ws.workflowstepname,csp.* from containerstepplan csp
left join workflowstep ws on ws.workflowstepid=csp.workflowstepid
left join specbase sb on sb.specbaseid=ws.specbaseid
left join spec s on s.specid=nvl(sb.revofrcdid,ws.specid)
where csp.containerid='{0}' and ws.workflowid='{1}'</string>.Value

        If DatabaseHelper.GetSingle(String.Format(strSpecPlan, containerId, newWorkflowId)) IsNot Nothing Then
            Return
        End If

        Dim oldSpecPlanDt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(strSpecPlan, containerId, oldWorkflowId))

        Dim newStepDt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(<string>select ws.workflowstepid,ws.workflowstepname,s.factoryid from workflowstep ws 
left join specbase sb on sb.specbaseid=ws.specbaseid
left join spec s on s.specid=nvl(sb.revofrcdid,ws.specid)
where ws.workflowid='{0}' </string>.Value, newWorkflowId))

        'yuxj20221108增加 s.factoryid并在插入时赋值
        Dim specPlanList As New ArrayList
        Dim specPlanSql = <string>insert into containerstepplan csp (csp.containerid,csp.containerstepplanid,csp.plannedfinishdate,csp.plannedstartdate,csp.workflowstepid,
csp.plantype,csp.islocked,csp.isshiplocked,csp.stepplancreatedate,csp.stepplancreateemployeeid,csp.stepplanshipdate,csp.stepplanshipemployeeid,specfactoryid,workflowstepname)
values ('{0}',sys_guid(),to_date('{1}','yyyy/mm/dd'),to_date('{2}','yyyy/mm/dd'),'{3}','{4}','{5}','{6}',to_date('{7}','yyyy/mm/dd hh24:mi:ss'),
'{8}',to_date('{9}','yyyy/mm/dd hh24:mi:ss'),'{10}','{11}','{12}') </string>.Value

        For Each specPlan As DataRow In oldSpecPlanDt.Rows
            Dim newStep = newStepDt.Select(String.Format("workflowstepname='{0}' and factoryid='{1}' ", specPlan("workflowstepname").ToString, specPlan("factoryid").ToString))
            Dim startDate = specPlan("plannedstartdate").ToString(), endDate = specPlan("plannedfinishdate").ToString()
            If Not String.IsNullOrWhiteSpace(startDate) Then
                startDate = Date.Parse(specPlan("plannedstartdate").ToString()).ToString("yyyy/MM/dd")
            End If
            If Not String.IsNullOrWhiteSpace(endDate) Then
                endDate = Date.Parse(specPlan("plannedfinishdate").ToString()).ToString("yyyy/MM/dd")
            End If
            If newStep.Length > 0 Then
                specPlanList.Add(String.Format(specPlanSql, containerId, endDate, startDate, newStep(0)("workflowstepid").ToString,
                                 specPlan("plantype").ToString(), specPlan("islocked").ToString(), specPlan("isshiplocked").ToString(),
                                 specPlan("stepplancreatedate").ToString(), specPlan("stepplancreateemployeeid").ToString(),
                                 specPlan("stepplanshipdate").ToString(), specPlan("stepplanshipemployeeid").ToString(), specPlan("factoryid").ToString, specPlan("workflowstepname").ToString))
                'yuxj20221108 对继承的数据，如果有新版的，删除旧版信息
                'specPlanList.Add(String.Format("delete from containerstepplan where containerid='{0}' and workflowstepid='{1}'", specPlan("containerid").ToString(), specPlan("workflowstepid").ToString()))
            End If

        Next

        DatabaseHelper.ExecuteSqlTran(specPlanList)

    End Sub

    '批次调度后插入批次操作日志信息 add zhunan 2022.6.24
    Public Sub InsertOperContainerInfo(ByVal para As System.Collections.Generic.Dictionary(Of String, String)) Implements IBusiness.uLMSContainerIBusiness.InsertOperContainerInfo
        Dim insertSql = <string>
INSERT INTO opercontainerrecord(containerid,containername,productname,productid,qty,operatorid,operreason,opertype,createdate)
VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',SYSDATE) 
                        </string>.Value
        insertSql = String.Format(insertSql, para("ContainerID"), para("ContainerName"), para("ProductName"), para("ProductID"), para("Qty"), para("OperatorId"), para("OperReason"), para("OperType"))
        DatabaseHelper.ExecuteSql(insertSql)
    End Sub

    ''' <summary>
    ''' 添加批次入库前的工艺 add by zhangrj 20220705
    ''' </summary>
    ''' <param name="containerId"></param>
    ''' <param name="bsWorkflowId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateContainerBsWorkflow(ByVal containerId As String, ByVal bsWorkflowId As String) As Boolean Implements uLMSContainerIBusiness.UpdateContainerBsWorkflow
        Dim strSql As String = "UPDATE containercurrentinfo c SET c.bsworkflowid = '{0}' WHERE c.containerid = '{1}'"
        strSql = String.Format(strSql, bsWorkflowId, containerId)
        Dim i As Integer = DatabaseHelper.ExecuteSql(strSql)
        If i > 0 Then
            Return True
        End If
        Return False
    End Function

    ''' <summary>
    ''' 获取同工艺已校对批次信息 add zhunan 2022.7.27
    ''' </summary>
    ''' <param name="workflowname">工艺名称</param>
    ''' <param name="workflowRevision">工艺版本</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetSameWorkflowVerifiedContainer(ByVal workflowname As String, ByVal workflowRevision As String) As DataTable Implements IBusiness.uLMSContainerIBusiness.GetSameWorkflowVerifiedContainer
        Dim strSql As String = <string>
SELECT wfb.workflowname,wf.workflowrevision,cci.isinstore,cci.containername,cci.techniqueemployeeid,cci.techniquedate
FROM container c 
INNER JOIN containercurrentinfo cci ON cci.containerid = c.containerid
LEFT JOIN workflow wf ON wf.workflowid = c.mfgworkflowid
LEFT JOIN Workflowbase wfb ON wfb.workflowbaseid = wf.workflowbaseid
WHERE wfb.workflowname = '{0}' AND wf.workflowrevision = '{1}' AND cci.techniquedate IS NOT NULL 
ORDER BY cci.techniquedate DESC
                               </string>.Value
        strSql = String.Format(strSql, workflowname, workflowRevision)
        Dim dt = DatabaseHelper.Query_ReturnDatTable(strSql)
        Return dt
    End Function

    ''' <summary>
    ''' 判断指定工艺的工序是否在平行作业工序之后
    ''' add:Wangjh 20220712
    ''' </summary>
    ''' <param name="containerID"></param>
    ''' <param name="workflowid"></param>
    ''' <param name="sequence"></param> 
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ContainerStepIsAfterPXZY(ByVal containerID As String, ByVal workflowid As String, ByVal sequence As Integer) As uMESProcessResult Implements uLMSContainerIBusiness.ContainerStepIsAfterPXZY
        Dim re = New uMESProcessResult
        re.Result = False

        Dim strSql = <String>select ut.attributevalue  from container c 
                    left join  userattribute ut  on ut.parentid=c.containerid and ut.userattributename='平行作业工序'
                    left join userattribute ut2 on ut2.parentid=c.containerid and ut2.userattributename='器材检验'
                    where c.containerid='{0}'  and ut.attributevalue is not null and ut2.attributevalue is null  </String>.Value
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, containerID))

        If dt.Rows.Count = 0 Then
            Return re
        End If
        Dim pxzygx = dt.Rows(0)("attributevalue").ToString '平行作业工序号
        Dim pxzygxSequence = 0

        strSql = <string>select ws.sequence from workflow w 
                    left join workflowstep ws on ws.workflowid=w.workflowid
                    left join specbase sb on sb.specbaseid=ws.specbaseid
                    left join spec s on s.specid=nvl(sb.revofrcdid,ws.specid)
                    where w.workflowid='{0}' and s.specno='{1}'</string>.Value

        dt = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, workflowid, pxzygx))
        If dt.Rows.Count = 0 Then
            Return re
        End If
        pxzygxSequence = Val(dt.Rows(0)("sequence").ToString) '平行作业工序号对应的顺序号

        If sequence >= pxzygxSequence Then
            re.Result = True
            re.Message = "存在平行作业工序号：" + pxzygx + "禁止调度到此工序号或之后"
            Return re
        Else
            Return re
        End If
    End Function

    ''' <summary>
    ''' 更新平行作业工序暂停批次
    ''' </summary>
    ''' <param name="param"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateParallelStepContainerHold(ByVal param As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.UpdateParallelStepContainerHold
        Dim strSql As String = <string>
SELECT k.specno FROM containercurrentinfo c
LEFT JOIN Userattribute u1 ON u1.parentid = c.containerid AND u1.userattributename = '平行作业工序'
LEFT JOIN Userattribute u2 ON u2.parentid = c.containerid AND u2.userattributename = '平行作业单号'
LEFT JOIN Userattribute u3 ON u3.parentid = c.containerid AND u3.userattributename = '器材检验'
LEFT JOIN (
 SELECT s.specno FROM workflowstep ws  
LEFT JOIN specbase sb ON sb.specbaseid=ws.specbaseid
LEFT JOIN spec s ON s.specid=NVL(sb.revofrcdid,ws.specid)
WHERE ws.workflowstepid = '{1}'
) k ON k.specno = u1.attributevalue 
WHERE (u3.attributevalue IS NULL OR u3.attributevalue = '') AND c.containerid = '{0}' AND k.specno IS NOT NULL and u1.attributevalue IS NOT NULL
                               </string>.Value
        strSql = String.Format(strSql.ToString, param("ContainerID").ToString, param("WorkflowStepID").ToString)
        Dim dtAttr As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
        '如果平行作业工序不为空
        If dtAttr.Rows.Count > 0 Then
            If OperContainerStop("'" + param("ContainerID").ToString + "'", "1") Then '更新总表字段（暂停）
                strSql = "SELECT cc.Productid,cc.qty,cc.productname FROM containercurrentinfo cc WHERE cc.containerid = '" + param("ContainerID").ToString + "'"
                Dim dtContainer As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
                Dim dic As New Dictionary(Of String, String)
                dic.Add("containerid", param("ContainerID").ToString)
                dic.Add("containername", param("ContainerName").ToString)
                dic.Add("productid", IIf(dtContainer.Rows.Count > 0, dtContainer.Rows(0)("ProductId").ToString, ""))
                dic.Add("productname", IIf(dtContainer.Rows.Count > 0, dtContainer.Rows(0)("productname").ToString, ""))
                dic.Add("operatorid", param("EmployeeID").ToString)
                dic.Add("operreason", "平行作业工序暂停")
                dic.Add("qty", IIf(dtContainer.Rows.Count > 0, dtContainer.Rows(0)("qty").ToString, ""))
                dic.Add("opertype", "2")
                Return AddDeleteContainerRecord(dic) '插入暂停记录
                Exit Function
            End If
        End If
        Return True
    End Function

    ''' <summary>
    ''' 特殊过程工序暂停 add by zhangrj 20220908
    ''' </summary>
    ''' <param name="param"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateSpecialStepContainerHold(ByVal param As Dictionary(Of String, String)) As Boolean Implements uLMSContainerIBusiness.UpdateSpecialStepContainerHold
        Dim strSql As String = <string>
SELECT ssr.indate FROM workflowstep ws 
left join specbase sb on sb.specbaseid = ws.specbaseid 
left join spec s on s.specid = nvl(sb.revofrcdid,ws.specid)
LEFT JOIN SpecialCourseSpecMapp scs ON scs.specid = s.specid AND scs.workflowid = '{0}'  
LEFT JOIN SpecialCourseSpecReport ssr ON ssr.specialcoursespecreportid = scs.specialcoursespecreportid 
WHERE ws.workflowstepid = '{1}' AND s.isspotcheck = '1' 
ORDER BY ssr.indate DESC
                               </string>.Value
        strSql = String.Format(strSql.ToString, param("WorkflowID").ToString, param("WorkflowStepID").ToString)
        Dim dtAttr As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
        '如果工序是特殊工序，且没有有效的特殊报告，暂停批次
        If dtAttr.Rows.Count > 0 Then
            Dim isHold = False
            If String.IsNullOrWhiteSpace(dtAttr.Rows(0)("indate")) Then '如果没有有效期，暂停
                isHold = True
            Else
                '如果有效期小于当前日期，则暂停
                If DateTime.Parse(dtAttr.Rows(0)("indate").ToString()) < DateTime.Parse(DateTime.Now.ToString("YYYY-MM-DD")) Then
                    isHold = True
                End If
            End If
            '更新批次暂停
            If isHold Then
                If OperContainerStop("'" + param("ContainerID").ToString + "'", "1") Then '更新总表字段（暂停）
                    strSql = "SELECT cc.Productid,cc.qty,cc.productname FROM containercurrentinfo cc WHERE cc.containerid = '" + param("ContainerID").ToString + "'"
                    Dim dtContainer As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
                    Dim dic As New Dictionary(Of String, String)
                    dic.Add("containerid", param("ContainerID").ToString)
                    dic.Add("containername", param("ContainerName").ToString)
                    dic.Add("productid", IIf(dtContainer.Rows.Count > 0, dtContainer.Rows(0)("ProductId").ToString, ""))
                    dic.Add("productname", IIf(dtContainer.Rows.Count > 0, dtContainer.Rows(0)("productname").ToString, ""))
                    dic.Add("operatorid", param("EmployeeID").ToString)
                    dic.Add("operreason", "特殊过程工序暂停")
                    dic.Add("qty", IIf(dtContainer.Rows.Count > 0, dtContainer.Rows(0)("qty").ToString, ""))
                    dic.Add("opertype", "2")
                    Return AddDeleteContainerRecord(dic) '插入暂停记录
                    Exit Function
                End If
            End If
        End If
        Return True
    End Function

    ''' <summary>
    ''' 判断批次的检测项是否全部完成录入，type=2判断检验序
    ''' add:Wangjh 20220902,modify:wangjh 检验序也得判断 add:Wangjh 2023/1/6
    ''' </summary>
    ''' <param name="conDt"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function JudgeContainerCheckPoint(ByVal conDt As DataTable, Optional ByVal type As String = "") As uMESProcessResult Implements uLMSContainerIBusiness.JudgeContainerCheckPoint
        Dim re = New uMESProcessResult
        re.Result = False
        If conDt.Rows.Count = 0 Then
            re.Result = True
            Return re
        End If

        Dim containerIds = ""
        For Each row In conDt.Rows
            containerIds += " cci.containerid='" + row("containerid").ToString + "' or"
        Next
        If containerIds <> "" Then
            containerIds = containerIds.Trim("r", "o")
        End If
        containerIds = "(" + containerIds + ")"

        Dim strSql = <string>select cci.containername,ws.workflowstepname,sc.name,sr.workerid,sr.checkerid
from stepcheckpoint sc
left join containercurrentinfo cci on {0}
left join stepcheckpointresult sr on sr.stepcheckpointid=sc.stepcheckpointid and sr.containerid=cci.containerid
left join workflowstep ws on ws.workflowstepid=sc.workflowstepid
left join specbase sb on sb.specbaseid=ws.specbaseid
left join spec s on s.specid=nvl(sb.revofrcdid,ws.specid)
where sc.workflowstepid='{1}'</string>.Value
        If type = "2" Then
            strSql += " and s.LASTCHECK=1 "
        End If
        strSql = String.Format(strSql, containerIds, conDt.Rows(0)("workflowstepid").ToString)
        If conDt.Columns.Contains("stepinfoid") Then '存在工步,工步目前只要有检测项，必须填写
            strSql += String.Format(" and sc.stepinfoid='{0}' ", conDt.Rows(0)("stepinfoid").ToString)
            Dim dt = DatabaseHelper.Query_ReturnDatTable(strSql)
            If dt.Rows.Count = 0 Then
                re.Result = True
                Return re
            Else
                Dim drs As DataRow()
                If type = "2" Then
                    drs = dt.Select("checkerid is null")
                Else
                    drs = dt.Select("workerid is null")
                End If
                If drs.Length = 0 Then
                    re.Message = "已录入"
                    re.Result = True
                Else
                    re.Message = "未录入"
                End If
                Return re
            End If
        Else '工序级则验证 edit by zhangrj 2022-10-17
            strSql += " and cci.containertype in (3,7) and (sc.qualitycheck = 1  OR (s.iskey = 1 AND sc.keycheck = 1) OR sc.checktype='5')"
            If type = "2" Then '检验判断
                strSql += " and sr.checkerid is null "
            Else
                strSql += " and sr.workerid is null "
            End If
            Dim dt = DatabaseHelper.Query_ReturnDatTable(strSql)
            If dt.Rows.Count = 0 Then
                re.Result = True
                Return re
            Else
                re.Message = "有关键过程或质保单或振动攻关检测项未录入完成"
                Return re
            End If
        End If


    End Function


    ''' <summary>
    ''' 判断批次的检测项是否全部完成录入（检验）
    ''' add:zhangrj 20221018
    ''' </summary>
    ''' <param name="conDt"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function JudgeContainerCheckPointByCheck(ByVal conDt As DataTable) As uMESProcessResult Implements uLMSContainerIBusiness.JudgeContainerCheckPointByCheck
        Dim re = New uMESProcessResult
        re.Result = False
        If conDt.Rows.Count = 0 Then
            re.Result = True
            Return re
        End If

        Dim containerIds = ""
        Dim containerstepworkreportIds = ""
        For Each row In conDt.Rows
            containerIds += " cci.containerid='" + row("containerid").ToString + "' or"
            containerstepworkreportIds += "'" + row("containerstepworkreportId") + "',"
        Next
        If containerIds <> "" Then
            containerIds = containerIds.Trim("r", "o")
        End If
        containerIds = "(" + containerIds + ")"
        containerstepworkreportIds = containerstepworkreportIds.Trim(",")

        Dim strSql = <string>select cci.containername,ws.workflowstepname,sc.name,sr.checkerid
 from stepcheckpoint sc
left join containercurrentinfo cci on {0}
left join stepcheckpointresult sr on sr.stepcheckpointid=sc.stepcheckpointid and sr.containerid=cci.containerid
left join workflowstep ws on ws.workflowstepid=sc.workflowstepid
left join specbase sb on sb.specbaseid=ws.specbaseid
left join spec s on s.specid=nvl(sb.revofrcdid,ws.specid)
where sc.workflowstepid='{1}' and sr.containerstepworkreportid IN ({2})</string>.Value
        strSql = String.Format(strSql, containerIds, conDt.Rows(0)("workflowstepid").ToString, containerstepworkreportIds)
        If conDt.Columns.Contains("stepinfoid") Then '存在工步,工步目前只要有检测项，必须填写
            strSql += String.Format(" and sc.stepinfoid='{0}' ", conDt.Rows(0)("stepinfoid").ToString)
        Else '工序级则验证 edit by zhangrj 2022-10-17
            strSql += " and cci.containertype in (3,7) and (sc.qualitycheck = 1  OR (s.iskey = 1 AND sc.keycheck = 1))"
        End If
        Dim dt = DatabaseHelper.Query_ReturnDatTable(strSql)
        If dt.Rows.Count = 0 Then
            re.Result = True
            Return re
        Else
            Dim drs = dt.Select("checkerid is null")
            If drs.Length = 0 Then
                re.Message = "已录入"
            Else
                re.Message = "未录入"
            End If
            Return re
        End If
    End Function

    ''' <summary>
    ''' 批次回退到上一序，验证
    ''' add:Wanjh 20220906
    ''' </summary>
    ''' <param name="containerId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ValidateContainerMoveBack(ByVal containerId As String) As uMESProcessResult Implements uLMSContainerIBusiness.ValidateContainerMoveBack
        Dim re As New uMESProcessResult
        re.Result = False

        Dim strSql = "select * from containercurrentinfo cci where cci.containerid='" + containerId + "' and cci.containerstatus=1 "
        Dim conbaseDt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql)
        If conbaseDt.Rows.Count = 0 Then
            re.Message = "未查询到批次基本信息"
            Return re
        End If
        Dim conBaseRow = conbaseDt.Rows(0)

        '转工验证
        '若当前序在转工第一序，不允许
        '若当前序在转工其他序，可以回退
        strSql = "select * from containershiprecordstep csrs where csrs.containershiprecordid ='" + conBaseRow("shipid").ToString + "' order by csrs.workflowstepid asc"
        Dim shipDt = DatabaseHelper.Query_ReturnDatTable(strSql)

        If shipDt.Rows.Count > 0 Then
            If shipDt.Rows(0)("workflowstepid").ToString = conBaseRow("workflowstepid").ToString Then '若当前序在转工第一序，不允许
                re.Message = "当前序在转工的第一序，请先撤销转工再回退"
                Return re
            End If
        End If

        '外委验证，存在外委不允许
        strSql = <stirng>select cm.* from containercommissioning cm 
left join workflowstep ws1 on ws1.workflowstepid=cm.workflowstepid
where cm.containerid='{0}' and ws1.workflowid='{1}' and cm.isuse=0 </stirng>.Value
        strSql += " and cm.workflowstepid<='{2}' and cm.inworkflowstepid>'{2}'"
        Dim cmDt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, containerId, conBaseRow("workflowid").ToString, conBaseRow("workflowstepid").ToString))

        If cmDt.Rows.Count > 0 Then
            re.Message = "当前序存在外委，请先撤销外委再回退"
            Return re
        End If

        '检验
        strSql = <string>select cci.containerid from containercheckinfo cci where cci.containerid='{0}' and cci.workflowstepid='{1}' and cci.isuse=0
union all
select cfci.containerid from containerfinishedcheckinfo cfci where cfci.containerid='{0}' and cfci.workflowstepid='{1}' and cfci.isuse=0 
union all
select cci.containerid from containercheckinfo2 cci where cci.containerid='{0}' and cci.workflowstepid='{1}' and cci.isuse=0 </string>.Value
        Dim checkDt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, containerId, conBaseRow("workflowstepid").ToString))
        If checkDt.Rows.Count > 0 Then
            re.Message = "当前序存在检验，请先撤销检验再回退"
            Return re
        End If
        '报工
        strSql = <string>select csw.containerid from containerstepworkreport csw where csw.containerid='{0}' and csw.workflowstepid='{1}' and csw.isuse=0
union all
select csw.containerid from containerstepworkreport2 csw where csw.containerid='{0}' and csw.workflowstepid='{1}' and csw.isuse=0
</string>.Value
        Dim cswDt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, containerId, conBaseRow("workflowstepid").ToString))
        If cswDt.Rows.Count > 0 Then
            re.Message = "当前序存在报工，请先撤销报工再回退"
            Return re
        End If
        '工区协作

        re.Result = True
        re.ReturnData = conbaseDt
        Return re

    End Function


#Region "yuxj20221201总体调度 增加处理enginepartplan 派工数，工序个数信息"
    Public Function UpdateEngineDispatchCount(ByVal containerid As String) As Boolean Implements uLMSContainerIBusiness.UpdateEngineDispatchCount
        UpdateEngineDispatchCount = False
        Dim strsql As String =
           "  update enginepartplan ep set ISUPDATE = 0,ep.stepdispatchcount=0,ep.workflowstepcount=0 where ep.concontainerid='{0}'"
        DatabaseHelper.ExecuteSql(String.Format(strsql, containerid))
        UpdateEngineDispatchCount = True
    End Function
#End Region

    ''' <summary>
    ''' 验证工步实测值录入是否有效（热表） add by zhangrj 20230619
    ''' </summary>
    ''' <param name="dr"></param>
    ''' <param name="checkType">0：报工验证，1：检验验证</param>
    ''' <param name="msg"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function IsValidRBCheckPointByStepinfo(ByVal dr As DataRow, ByVal checkType As Integer, ByRef msg As String) As Boolean Implements uLMSContainerIBusiness.IsValidRBCheckPointByStepinfo
        Dim strSql = <string>SELECT sr.workerid,sr.checkerid from stepcheckpoint sc
LEFT JOIN stepcheckpointresult sr on sr.stepcheckpointid=sc.stepcheckpointid and sr.containerid {0}
WHERE sc.workflowstepid='{1}' AND sc.stepinfoid = '{2}'</string>.Value
        Dim containerSql = String.Empty

        If String.IsNullOrWhiteSpace(dr("containerId").ToString()) Then '如果Id为空，表示合卡批次
            containerSql = String.Format("IN (SELECT cb.containerid FROM containercombinate cb WHERE cb.containercombinatename ='{0}')", dr("containerName").ToString())
        Else
            containerSql = String.Format("= '{0}'", dr("containerId").ToString())
        End If
        Dim dt = DatabaseHelper.Query_ReturnDatTable(String.Format(strSql, containerSql, dr("workflowstepid").ToString(), dr("stepinfoid").ToString()))
        '如果不存在检测项，则不验证
        If dt.Rows.Count = 0 Then
            Return True
        End If
        '验证是否录入
        If checkType = 0 Then
            '如果存在工人未录入，则提示未录入
            If dt.Select("workerid is null").Length > 0 Then
                msg = "未录入"
                Return False
            Else
                msg = "已录入"
                Return True
            End If
        ElseIf checkType = 1 Then
            '如果存在检验未录入，则提示未录入
            If dt.Select("checkerid is null").Length > 0 Then
                msg = "未录入"
                Return False
            Else
                msg = "已录入"
                Return True
            End If
        End If
        Return True
    End Function

    ''' <summary>
    ''' 通过单个批次ID查询其合批下的所有批次 add by zhangrj 20230619
    ''' </summary>
    ''' <param name="containerID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetCombinateContainerDetail(ByVal containerID As String) As DataTable Implements uLMSContainerIBusiness.GetCombinateContainerDetail
        Dim sql = <string>
                    SELECT c.containerid,c.containername,c.containertype
                    FROM containercombinate cb 
                    LEFT JOIN containercombinate cb1 ON cb1.containercombinatename = cb.containercombinatename
                    LEFT JOIN containercurrentinfo c ON c.containerid = cb1.containerid and c.containerstatus = 1
                    WHERE cb.containerid = '{0}'
                  </string>.Value
        Return DatabaseHelper.Query_ReturnDatTable(String.Format(sql, containerID))
    End Function

    ''' <summary>
    ''' 通过合批名查询合批下的所有批次 add by zhangrj 20230619
    ''' </summary>
    ''' <param name="combinateName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetCombinateContainerDetailByName(ByVal combinateName As String) As DataTable Implements uLMSContainerIBusiness.GetCombinateContainerDetailByName
        Dim sql = <string>
                    SELECT c.containerid,c.containername,DECODE(c.isinstore,-1,cc.mfgworkflowid,0,c.workflowid,c.bsworkflowid) workflowid
                    ,c.mfgordername,c.productname,c.workflowname,c.qty,cc.originalstartdate createdate,c.isinstore,c.workflowstepname,
                    c.containertype,c.workflowstepid,'1' iscombinate
                    FROM containercombinate cb 
                    LEFT JOIN containercurrentinfo c ON c.containerid = cb.containerid and c.containerstatus = 1
                    LEFT JOIN container cc ON cc.containerid = c.containerid
                    WHERE cb.containercombinatename = '{0}'
                  </string>.Value
        Return DatabaseHelper.Query_ReturnDatTable(String.Format(sql, combinateName))
    End Function

    ''' <summary>
    ''' 判断是否是合卡批次 add by zhangrj 20230703
    ''' </summary>
    ''' <param name="container">批次ID或批次名</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function IsCombinateContainer(ByVal container As String) As Boolean Implements uLMSContainerIBusiness.IsCombinateContainer
        Dim strSql = <string>
                         SELECT 1 FROM containercombinate cb 
                         WHERE Upper(cb.containerid)=Upper('{0}') OR Upper(cb.containername)=Upper('{0}')
                     </string>.Value
        strSql = String.Format(strSql, container)
        If DatabaseHelper.GetSingle(strSql) Is Nothing Then
            Return False
        Else
            Return True
        End If
    End Function
    ''' <summary>
    ''' 获取父卡的信息（通过子卡的批次ID）add by zhangrj 20230704
    ''' </summary>
    ''' <param name="containerId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetFaContainerInfoBySubContainerID(ByVal containerId As String) As DataTable Implements uLMSContainerIBusiness.GetFaContainerInfoBySubContainerID
        Dim strSql = <string>
                        SELECT DISTINCT c.containerid,c.containername FROM containersubcontainer csc 
                        LEFT JOIN container c ON c.containerid = csc.containerid
                        WHERE csc.subcontainerid = '{0}'
                     </string>.Value
        strSql = String.Format(strSql, containerId)
        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 保存批次属性信息
    ''' add:Wangjh 2023-8-11
    ''' </summary>
    ''' <param name="containerId"></param>
    ''' <param name="attrName"></param>
    ''' <param name="attrValue"></param>
    ''' <remarks></remarks>
    Public Sub SaveContainerAttr(ByVal containerId As String, ByVal attrName As String, ByVal attrValue As String) Implements uLMSContainerIBusiness.SaveContainerAttr
        Dim strSql = <string>declare 
v_count number;
begin
  select count(1) into v_count from containerattribute ca where ca.containerid='{0}' and ca.attributename='{1}';
  if v_count=0 then
    insert into containerattribute ca (ContainerAttributeID,ContainerID,ATTRIBUTENAME,ATTRIBUTEVALUE)
    values (sys_guid(),'{0}','{1}',:ATTRIBUTEVALUE);
  else
      update containerattribute ca set ca.attributevalue=:ATTRIBUTEVALUE where ca.containerattributeid IN (
      select ca.containerattributeid from containerattribute ca where ca.containerid='{0}' and ca.attributename='{1}');
  end if;
  commit;
end;</string>.Value
        Dim insertpar(0) As OracleParameter

        insertpar(0) = DatabaseHelper.NewParameter(":ATTRIBUTEVALUE", attrValue, OracleType.Clob)
        DatabaseHelper.ExecuteSql(String.Format(strSql, containerId, attrName), insertpar)

    End Sub

    ''' <summary>
    ''' 记录批次定时日志
    ''' add:Wangjh 20230908
    ''' </summary>
    ''' <param name="id">定时任务id</param>
    ''' <param name="containerid"></param>
    ''' <param name="containername"></param>
    ''' <param name="msg"></param>
    ''' <param name="taskType">类型</param>
    ''' <param name="emp">执行人</param>
    ''' <remarks></remarks>
    Public Sub WriteContainerSCLog(ByVal id As String, ByVal containerid As String, ByVal containername As String, ByVal msg As String, ByVal taskType As Integer, ByVal emp As String) Implements uLMSContainerIBusiness.WriteContainerSCLog
        Dim strSql = <string>begin
  update ContainerScheduledTaskLogs cl set cl.islatest=0 where  cl.containerid='{1}' and TaskType={4} and Islatest=1;
  insert into ContainerScheduledTaskLogs cl (ContainerScheduledTaskLogsID,scheduledtaskid,ContainerID,Containername,
  IsLatest,LogMessage,CreateDate,TaskType,CreateEmp) values (sys_guid(),'{0}','{1}','{2}',1,'{3}',sysdate,{4},'{5}');
  commit;
end;</string>.Value
        DatabaseHelper.ExecuteSql(String.Format(strSql, id, containerid, containername, msg, taskType, emp))
    End Sub

    ''' <summary>
    ''' 删除批次定时日志
    ''' add:Wangjh 20230908
    ''' </summary> 
    ''' <param name="containerid"></param>
    ''' <param name="taskType">类型</param>
    ''' <remarks></remarks>
    Public Sub DeleteContainerSCLog(ByVal containerid As String, ByVal taskType As Integer) Implements uLMSContainerIBusiness.DeleteContainerSCLog
        DatabaseHelper.ExecuteSql(String.Format(<string>delete ContainerScheduledTaskLogs cl where cl.containerid='{0}' and cl.tasktype={1}</string>.Value, containerid, taskType))
    End Sub

End Class
